#include // Paul Taylor CS200 program const double lpg = 0.264179; // lpg = liter per gallon void main() { using namespace std; char choice; do { using namespace std; double mpg_calc(double, double); // provide liters used then miles traveled & function returns a double that represents the mpg double liters, gasoline, car1, car2; cout << "\nWould you like to run a program to compare the fuel efficiency\n" << "between two different cars? Enter Y for yes or N for no then press Enter.\n"; cin >> choice; if (choice == 'Y' || choice == 'y') { for (int i = 0; i<2; i++) { cout << "Enter total # of liters your car has consumed at last fill up & press Enter\n"; cin >> liters; cout << "Enter total # of miles traveled by your car since last fill up & press Enter\n"; cin >> gasoline; cout << "Your car achieved " << mpg_calc(liters, gasoline) << " miles per gallon since last fill up.\n\n"; if (i == 0) car1 = mpg_calc(liters,gasoline); else car2 = mpg_calc(liters,gasoline); } if (car1 > car2) cout << "The first car with an average of " << car1 << " mpg is the most fuel economical.\n"; else cout << "The second car with an average of " << car2 << " mpg is the most fuel economical.\n"; } else cout << "Thank you & bye bye.\n"; } while (choice == 'Y' || choice == 'y'); } double mpg_calc(double l, double m) { return (m / ( l * lpg )); } /* Would you like to run a program to compare the fuel efficiency between two different cars? Enter Y for yes or N for no then press Enter. y Enter total # of liters your car has consumed at last fill up & press Enter 264179 Enter total # of miles traveled by your car since last fill up & press Enter 1 Your car achieved 1.43286e-005 miles per gallon since last fill up. Enter total # of liters your car has consumed at last fill up & press Enter 1 Enter total # of miles traveled by your car since last fill up & press Enter 1 Your car achieved 3.78531 miles per gallon since last fill up. The second car with an average of 3.78531 mpg is the most fuel economical. Would you like to run a program to compare the fuel efficiency between two different cars? Enter Y for yes or N for no then press Enter. y Enter total # of liters your car has consumed at last fill up & press Enter 20 Enter total # of miles traveled by your car since last fill up & press Enter 200 Your car achieved 37.8531 miles per gallon since last fill up. Enter total # of liters your car has consumed at last fill up & press Enter 40 Enter total # of miles traveled by your car since last fill up & press Enter 200 Your car achieved 18.9266 miles per gallon since last fill up. The first car with an average of 37.8531 mpg is the most fuel economical. Would you like to run a program to compare the fuel efficiency between two different cars? Enter Y for yes or N for no then press Enter. y Enter total # of liters your car has consumed at last fill up & press Enter 40 Enter total # of miles traveled by your car since last fill up & press Enter 250 Your car achieved 23.6582 miles per gallon since last fill up. Enter total # of liters your car has consumed at last fill up & press Enter 50 Enter total # of miles traveled by your car since last fill up & press Enter 250 Your car achieved 18.9266 miles per gallon since last fill up. The first car with an average of 23.6582 mpg is the most fuel economical. Would you like to run a program to compare the fuel efficiency between two different cars? Enter Y for yes or N for no then press Enter. n Thank you & bye bye. Press any key to continue . . . */