Variable declaration problem to compile in Code::Blocks

Asked

Viewed 419 times

-4

#include <stdio.h>
#include <locale.h>
#include <string.h>

int main () {

    setlocale (LC_ALL,"Portuguese");

    int num,escolha; char nome[20];

    printf ("\nDigite seu nome: ");
    gets (nome);

    printf ("\nInforme um número: ");
    scanf ("%d",&num);

    printf ("\nDigite 1 para ver os números pares ou 2 para ver os números ímpares: ");
    scanf ("%i",&escolha);

    switch (escolha){
        case 1: for (int i = 0; i < num; i ++){
                    if (i%2==0){
                        printf ("\n%i",i); } }
        break;

        case 2: for (int h = 0; h < num; h ++){
                    if (h%2==1){
                        printf ("\n%i",h); } }
        break;

        default: printf ("\nOpção invalida.");
    }

    num % 2==0 ? printf("\n\n%s o número digitado por você é par !\n\a",nome) : printf("\n\n%s o número digitado por você é ímpar !\n\a",nome);

    getchar ();

    return 0;
}

Someone can tell me why this code compiles in dev, but in Blocks it gives this error ( ps has already happened with several codes this stop not to compile and use it because as I read in cprogressivo.net it has far more advantages than others ) :

Antes de reclamar a imagem está em png !

The compiler : mingw

Do code::blocks

1 answer

2


In Code Blocks go to: Project -> Build Options -> Compiler Settings -> Other Options there puts the -std=99 or std=c11, as the compiler himself instructed him.

So just follow the instructions given and "poke around" in the IDE. I didn’t need to research anything, much less watch videos, they don’t teach anyone to program.

It may be that other errors appear, for example, there may be an indication not to use gets(). Even if it doesn’t appear, it’s good advice. Another good advice is to better organize the code. It’s hard to say what he does even if it’s a simple example, imagine when he does bigger things. Keep a pattern, put in rows new blocks. There are times that space too much, there are times that save on spacing. Although I like the conditional operator, it should not be used whenever it has a if. Interestingly in this case it might even be used, but inside the printf(), not as a choice of which one to execute.

  • I put everything in order, the code is with the identation ok, just missed the comments so what am I doing wrong ? ( valeu I will not use gets ! )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.