The reason that happens is because the checks will happen one after another from top to bottom. Since it's an if-else-if-else structure, that means the check for m <= 900 happens first. Think about it, if m is 500 then the first successful check will be that if (m <= 900) since 500 is less than 900. If you're going to keep the conditional expressions you're using, you need to check if m <= 780 first because if it's not, then it must be greater than 780. Next, you'd check if m is in the next tier, m <= 840. If it's not, then only would you check if it's <= 900.
The question now is: What should your program do if m > 900? Right now it will do nothing.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
PB: did you find what errors I was trying to point out?
I prefer to use < and > rather than ≤ and ≥ because I think the simpler operators are easier to read. In this case I would write the cases in the opposite order:Note there is no need for an if in the last else.
No. You have too many tests; you don't need to mention 840 twice. Each occurrence of 840 is an opportunity for an error to occur, and mixing > and <= provides you with more opportunities to introduce errors.
What happens if you get a mark of 901?
I think I'll just lie down here for a second. And ponder this tiny ad: