#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
for (int execution = 1; execution <= 2; execution++)
{
double beginningRead, endingRead, reqGallons, avgMPG, price1, price2, price3, avgPPG, OneMileTrip;
char answer = 'y';
double totalMiles = 0, gallonsPurchased = 0;
int count = 0;
while (answer == 'y' || answer == 'Y')
{
first:
cout << "Enter the beginning odomerter reading: ";
cin >> beginningRead;
if (count != 0 && beginningRead <= endingRead)
{
cout << "Your beginning odometer reading must be greater than the prior ending odometer reading.\n";
goto first;
}
count++,
cout << "Enter the ending odometer reading: ";
cin >> endingRead;
if (endingRead < beginningRead)
{
cout << "The ending odometer reading must be greater than the beginning odometer reading.\n";
goto first;
}
second:
cout << "Enter the gallons required for your full-up: ";
cin >> reqGallons;
if (reqGallons <= 0)
{
cout << "The required amount of gallons must be greater than 0.\n";
goto second;
}
totalMiles += (endingRead - beginningRead);
gallonsPurchased += reqGallons;
cout << "Enter y to enter more readings or n to continue: ";
cin >> answer;
}
cout << "\n";
avgMPG = totalMiles/gallonsPurchased;
for ( int station = 1; station <= 3; station++)
{
cout << "Enter the price per gallon at station #" << station << ": $";
if (station == 1)
{
cin >> price1;
}
if (station == 2)
{
cin >> price2;
}
if (station == 3)
{
cin >> price3;
}
}
avgPPG = (price1 + price2 + price3) / 3;
OneMileTrip = avgPPG / avgMPG;
cout << "\nYour car's average mile per gallon is: " << avgMPG << " mpg" << endl;
cout << "You bought gas at an average $" << setprecision(2) << fixed << avgPPG << " per gallon\n";
cout << "The cost for your car to go 1 mile is $" << setprecision(2) << fixed << OneMileTrip << endl;
if (avgMPG > 0 && avgMPG <= 15)
{
cout << "Your car is very inefficient.\n\n\n";
}
if (avgMPG >= 16 && avgMPG <= 30)
{
cout << "Your car's efficiency is OK.\n\n\n";
}
if (avgMPG >= 31)
{
cout << "Your car is very efficient.\n\n\n";
}
}
system ("pause");
return 0;
}