MPG Algorithm
Gas Mileage Algorithm
Miles Per Gallon
The miles per gallon is the number of miles driven, divided by the number of gallons used. For example if you drive 100 miles and use 5 gallons, the MPG is 20.
- In order to find the number of miles driven you will need the starting odometer reading and the final odometer reading.
- To find the number of gallons used you need to start with a full tank, and then see how many gallons it takes to fill it back up.
Algorithm for Finding Miles per Gallon:
- Go to a gas station and fill the car (until the pump clicks off.)
- Write down the odometer reading. We will call this startOdometer.
- Drive until you need gas again.
- Go to a gas station and fill the car (until the pump clicks off.)
- Write down the odometer reading. We will call this finalOdometer.
- Write down how many gallons you put in. We will call this gallons.
Now do the calculation.