Quote:
Originally Posted by DewMan
The simplest thing would be to reverse your logic.
Check for the lowest value first, and the highest value last. Your value will get updated at each intermediate step that the check is valid.
if (score > 60)
grade = d
if(score > 70)
grade = c
if(score > 80)
grade = b
if(score > 90)
grade = a
|
its simple, but bad programming. if you have a high proportion of good students and/or hit the loop a large number of times you are reassigning your variables 3-4 times per loop. plus forcing the evaluation of the if statement every loop. at least with an if/else loop it drops out of the evaluation once it hits a match.
i think Dilbert1234567's solution is the best.