Back to Challenge Set 16

Code Challenge: Fuel Check

Difficulty  

divider

The Brief

What they asked for
Before each flight we check whether there is enough fuel
for the trip plus a reserve. Distance, fuel on board, and
how efficient the aircraft is. Tell me go or no-go, and
if it is no-go tell me how short we are.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Three parameters, all numbers — so a swap builds fine and gives a confident wrong answer, as in Activity 2.5. Write the order down, and say which parameter changes the answer most.
  • The reserve is not given to you. Pick one, record it, and apply it consistently.
  • Have the method return how short you are (zero or less when there is enough), and let the main program decide GO or NO-GO. A no-go should say how short, not just no.

Sample Output

Sample Output
Distance: 900 Fuel: 210 Efficiency: 4.5
NO-GO. Short by 10.0 units including reserve.

900 ÷ 4.5 is 200 units for the trip, and the sample's reserve is 10% of that, so 220 are needed against 210 on board. Test a GO case too.


Submit

Your requirements list and your program file, named cc-fuel-check.

Commence Challenge