john k john k - 1 year ago 92
C Question

If else statement doesn't work in C


void main()
char grade[1];

//Data Input
enter code here
printf("Enter a grade{A,B,C,D,F]: ");

//If Statement

printf("The score for the grade 'A' is 4.00");
if(grade=='b '=='B')
printf("The score for the grade 'B' is 3.00");
printf("The score for the grade 'C' is 2.00");
printf("The score for the grade 'D' is 1.00");

I try it so many times but the if else statement just didn't pop up
I trying to make the program recognize both upper case and lower case of the grade A-F or a-f. but it didn't seem to work

Enter a grade{A,B,C,D,F]: a

Process returned 1 (0x1) execution time : 2.599 s
Press any key to continue.

gives me this

Answer Source

It doesn't fail. Your comparison fails. You are saying:

If grade is equal to 'a' AND 'a' is equal to 'A'....

Which can never be true. Try:

if(grade == 'a' || grade == 'A')...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download