samedi 1 décembre 2018

Compiler Error in C - expected ‘;’ before ‘{’ token after ELSE statement

Here’s a newbie question. I’m writing this simple if...else code, but the gcc compiler acuses that the ';' token is missing right after the else expression, even though I’ve never seen any C if...else code examples that includes this specific token before the function’s curly braces. Also, when I include the token after the 'else' function, the terminal outputs both if and else elements, so I’m completely lost here.

Compiler Error:

cclasses.c:15:2: error: expected ‘;’ before ‘{’ token

Code:

#include <stdio.h>
#include <stdbool.h>

int main ()
{
        int x;
        printf("\nEnter with negative or positive int.");
        scanf("%i", &x);

        if (x > 0)
        {
                printf("\nYou've entered positive int: %i\n", x);
        }
        else(x < 0)
        {
                printf("\nYou've entered negative int: %i\n", x);
        }

        printf("\nEND OF PROGRAM.\n");
        return 0;
}

Aucun commentaire:

Enregistrer un commentaire