+ 2

What is the problem with this if-else-if statement?

Soooooo, in my program which determines what grade is whatever number the user inputs, unless the number I input is over 70, it's keep saying that my grade is a B, even though it's not. I being very confused. Here's the code: https://code.sololearn.com/cnfTQlA51aqo/#cpp

26th Aug 2019, 10:19 PM
CeePlusPlus
CeePlusPlus - avatar
3 Antworten
+ 2
The syntax you use is only possible in python I think... This: 60 <= grade < 70 is basically the same like: (60 <= grade )< 70. Because (60<=grade) is true or false, it will be castet to an int (0 or 1) . But 0 or 1 will be smaller than 70, no matter what you enter. E.g. if you enter 100 you should get A as result, to correct the else if, you should change it to: 60 <= grade && grade < 70 (the other in the same way...)
26th Aug 2019, 10:40 PM
Niwo
Niwo - avatar
+ 2
Niwo thx
26th Aug 2019, 10:43 PM
CeePlusPlus
CeePlusPlus - avatar
0
np
26th Aug 2019, 10:45 PM
Niwo
Niwo - avatar