The current code displays 550.50 miles as £2252.00. Not the correct sum of £2326.25. |
I think the algorithm is not being interpreted correctly.
If the distance is up to 100 miles, the cost is simply miles * RATE1 + 50.
For any greater distance, then more than one rate needs to be applied, e.g. if the distance is between 100 and 500, the cost is 100 * RATE1 + (miles - 100) * RATE2 + 50; and for longer distances, all three rates are used.
At least I think that's how it should work.
Also, since the title of the thread is about IF statements, you should simplify the way this is done.
The first test
if (miles <= 100)
is correct.
The second, there's no need to test
miles >= 100
, it must be greater than 100, that's what the 'else' does. Similarly the last condition
if (miles > 500)
is redundant and should be removed, the final 'else' simply picks up everything not matching the first two tests.