0

i got an if statement that will display the letter A and the percent grade if there percent grade is between 90 and 100. and the else statement will do the same but its display a B if the grade is between 80 and 90, my problem is, even if the grade percentage comes out as a 50%, it only displays the first IF statement and says the person who got a 50% got a A which def. is not right so idk what im doing wrong with this code

total=totalPoints/eightfiftytotal*100;
	

// display the grade letter and grade percentage

		printf("Grade     ||     Percentage\n\n");

	if((int) total > 90 || total < 100) {
		printf("%c           %d percent\n ", gradeLetter1, (int) total);
	}
	
		else if ((int) total > 80 || total < 89) { 
			printf("%c", gradeLetter2, (int) total);
		}
4
Contributors
6
Replies
10
Views
6 Years
Discussion Span
Last Post by mtatadotcom
0

Right away I see a problem...What if you enter 90 or 100, how does your program handle that. You should be saying, A is a grade from 90 to 100.

if (total >= 90)

Edited by gerard4143: n/a

0

Right away I see a problem...What if you enter 90 or 100, how does your program handle that. You should be saying, A is a grade from 90 to 100.

if (total >= 90)

good point. But I dont think that still helps why it always displays the first IF statement still even if its below 90

0

It should be (condition && condition) not (condition || condition). All grades(except 100) will be less than 100 so your first condition will always be true.

Edited by gerard4143: n/a

0

if((int) total > 90 || total < 100)

the logical operator OR is not very efficient at traping a number in certain boundaries, because. only one of the two conditions to be true to conclude that the condition is valid to proceed, so if you enter 50

total < 100

is valid and if you enter 101

total > 90

so your first if statement is always valid

if you use AND operator

if( total > 90 && total < 100

then both conditions must be reached for the compiler to declare that condition valid

0

but since it doesn't satisfy the second compare the compiler will consider the condition invalid

try using the && operator pal don't use the ||

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.