Variable declaration problem to compile in Code :: Blocks

-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 knows to tell me why this code compiles in the dev, but in the blocks it gives this error (ps already happened with several codes that stop not compile and use it because as I read in cprogressivo.net it has much more advantages than others):

Thecompiler:mingw

    
asked by anonymous 12.06.2016 / 23:01

1 answer

2

No Code Blocks go to: Project -> Build Options -> Compiler Settings -> Other Options there put -std=99 or std=c11 , as the compiler itself instructed.

So just follow the instructions given and "fuck" in the IDE. No need to search anything, much less watch videos, they do not usually teach anyone to program.

Other errors may appear, for example, there may be an indication not to use gets() . Even if it does not appear, it's good advice. Another good advice is to better organize the code. It's hard to say what he does even as a simple example, imagine when you do bigger things. Keep a pattern, put in new lines new blocks. You have too much space, you have, time that saves in spacing. Although I like the conditional operator, it should not be used without it having a if . Interestingly in this case it could even be used, but within printf() , not how to choose which one to execute.

    
12.06.2016 / 23:16