Back to Set 1

Code Challenge: Fuel Range

Difficulty  

divider

The Brief

What they asked for
Before a long drive I want to know if I can make it. Ask me
how much fuel is in the tank, how far the car goes on a
tank, and how far I am driving, and tell me how much is
left over.

Write your requirements list before you write any code. What goes in, what gets worked out, what comes out, and every question the brief did not answer.


Notes

  • You cannot tell them whether they make it yet — that is a decision, and decisions arrive at session 9. Report the number and let them read it.
  • A negative left-over is a real answer and it is the interesting one. Do not hide it.
  • Pick your units and say so in the output. A number with no unit is not an answer.
  • The brief does not mention a reserve. Real drivers keep one. Decide whether yours does and write it in the requirements list.

Sample Output

Sample Output
Fuel in the tank (litres): 32 [Enter]
Kilometres per litre: 13 [Enter]
Distance to drive: 380 [Enter]
Range: 416 km
Left over after the trip: 36 km

Test a trip that does not fit. The output should still make sense.


Submit

Your requirements list and your program folder, named cc-fuel-range.

Commence Challenge