I have to compare a set of lines of code for homework...
I have:
if (Sales >= 500.00)
total = 25.00 + .11 * Sales;
and also
if (Sales >= 500.00)
total = 25.00 + .11 * Sales;
else if (Sales >= 1000.00)
total = 37.00 + .27 * Sales;
Both yield the exact same results whatever number you put inside them, but the question asks me which one is better and why?
I'm thinking maybe the second set? because all of the && stuff is redundant as the second program would just go to the next one automatically without being asked?
I'm thinking maybe the second set? because all of the && stuff is redundant as the second program would just go to the next one automatically without being asked?
I like your answer. The second one is better because it:
- is more clear (I'd rather read the shorter one)
- is easier to maintain (notice how the value is also repeated in the test)
- lacks the redundant tests