Search code examples
cif-statementstring-literals

Why does my if statement work, but my else doesn't?


Sorry if this has been asked before or is a stupid question, but I'm new to both the site and C. So, when I run this code, when I type an answer, any answer, be it right or wrong, it says what it's supposed to say when for the if statement.

Here's the code:

#include <stdio.h>
int main()
{
    int x;
    printf("1+1=");
    scanf("%d", &x);
    if("x==2"){
        printf("Watch out, we got a genius over here!");
    }
    else {
        printf("I don't even know what to say to this...");
    }
    return 0;
}

Solution

  • you need

    if(x==2) 
    

    without the quotes