Program Issue, if and else if statements

Printable View

• 03-29-2008
kordric
Program Issue, if and else if statements
For some reason everytime i run my program the answer is always B. Im not sure why this is, please help!

Code:

```    //Figure out letter grade     if (the_student.percentTotal>= 90)     {         the_student.letterGrade = 'A';                              }     else if ((the_student.percentTotal>= 80) || (the_student.percentTotal < 90))     {         the_student.letterGrade = 'B';     }     else if ((the_student.percentTotal>= 70) || (the_student.percentTotal < 80))     {         the_student.letterGrade = 'C';     }     else if ((the_student.percentTotal>= 60) || (the_student.percentTotal < 70))     {         the_student.letterGrade = 'D';     }     else if (the_student.percentTotal<60)     {         the_student.letterGrade = 'F';     }```
• 03-29-2008
tabstop
Can you come up with a number, call it percentTotal, where the if before the "B" clause is false? (Hint: No.) (Double hint: || does not mean "and".)
• 03-29-2008
anon
In addition, if you have established that n >= 90 is not true (the first condition is false), there is no point checking in the else block if n is smaller than 90. You wouldn't have got to the else block if it wasn't so.
Similarly for all comparisons down the chain.