A documented (commented) program that computes the fuel efficiency of a multi-leg journey. The program will prompt for the starting
Question:
A documented (commented) program that computes the fuel efficiency of a multi-leg journey.
- The program will prompt for the starting odometer reading and then get information about a series of legs.
- For each leg, the user enters the current odometer reading and the amount of gas used.
- The user signals the end of the trip by entering -1 for either one of them.
- The program should print out the miles per gallon achieved on each leg and the total miles per gallon (MPG) for the trip.
Two sample runs for the program are as follows.
Sample Run 1
Please enter the starting odometer reading: 100
Please enter your odometer reading and gallons of gas used on each leg of the trip.
When you have entered data for all the legs, then enter -1 for any of them.
Enter odometer reading: 200
Enter gallons used: 5
Enter odometer reading: 400
Enter gallons used: 8
Enter odometer reading: 500
Enter gallons used: -1
The mpg for leg 1 of the journey is: 20.0
The mpg for leg 2 of the journey is: 25.0
The total mpg for this trip is: 23.08
Sample Run 2
Please enter the starting odometer reading: 350
Please enter your odometer reading and gallons of gas used on each leg of the trip.
When you have entered data for all the legs then enter -1 for any of them.
Enter odometer reading: 500
Enter gallons used: 4
Enter odometer reading: 750
Enter gallons used: 9
Enter odometer reading: -1
Enter gallons used: 6
The mpg for leg 1 of the journey is: 37.5
The mpg for leg 2 of the journey is: 27.78
The total mpg for this trip is: 30.77
Financial Algebra advanced algebra with financial applications
ISBN: 978-0538449670
1st edition
Authors: Robert K. Gerver