-
IF else statement help
I need help with the following program
Something is wrong and whatever i type, the output is always "You answer is incorrect!"
Code:
#include <stdio.h>int main()
{
/*quiz*/
char ANS[100];
printf("What is the name of the President of the United States?\n");
scanf("%s", ANS);
if(ANS == "Donald")
{
printf("Your answer is correct!");
}
else
{
printf("Your answer is incorrect!");
}
return 0;
}
-
You need to use strcmp() to compare strings.
-
Your mistake is that ;
You cant use ANS = "String" with this way . You must try like that
if (ANS[0] == 'D' && Donald[0] == 'o' && .... )
or you should use strcompare .