'Ask the user for the data. . . . 'Calculate mpg for first tank of gas. LET MPG1 = (SECONDMILES - FIRSTMILES) / GALLONS1 'Calculate mpg for second tank of gas. LET MPG2 = (THIRDMILES - SECONDMILES) / GALLONS2 'Calculate the difference between mpg rats. 'Write out the result. END
It might seem odd that the second odometer reading,
SECONDMILES
, is used in both
the first calculation and the second calculation.
Consider an example:
FIRSTMILES
— First odometer reading = 25000SECONDMILES
— Second odometer reading = 25300THIRDMILES
— Third odometer reading = 25650SECONDMILES
- FIRSTMILES
= 25300 - 25000 = 300THIRDMILES
- SECONDMILES
= 25650 - 25300 = 350
The two miles-per-gallon rates, MPG1
and MPG2
have been calculated.
Now finish the program by filling in the last two steps:
(Type your answers in the boxes privided, or just write them on a scrap of paper.)