High Level Language Programming


Average Miles Per Gallon Algorithm in C++

 1 // program MPG
 2 #include <iostream.h>
 3 void main()
 4 {
 5    int starting_mileage, ending_mileage, distance_driven;
 6    double gallons_used, average_miles_per_gallon;
 7    cin >> gallons_used;
 8    cin >> starting_mileage;
 9    cin >> ending_mileage;
10    distance_driven = ending_mileage - starting mileage;
11    average_miles_per_gallon = distance_driven / gallons_used;
12    cout << "MPG is "
           << average_miles_per_gallon
           << "." << endl;
13 } // end main
 


[Prev][TOC][Next]


CS1104 Main Page
Last Updated 01/05/2000
© L.Heath, 2000