/* tripCost.cpp calculates the total cost and miles per gallon 
 * of a vehicle, based on the miles traveled, fuel consumed,
 * cost per gallon of fuel, and operating cost per mile.
 *
 * Input: The total miles traveled, total fuel consumed,
 *         unit cost of the fuel, and operating cost per mile.
 * Precondition: miles, gallonsOfFuel, unitFuelCost and 
 *         unitOperatingCost are all positive.
 * Output: The miles per gallon, total cost of the trip
 *         and the cost per mile.
 ***************************************************************/

#include <iostream>         // cin, cout, <<, >>, fixed, showpoint
#include <iomanip>          // setw(), setprecision()
#include <cassert>
using namespace std;

int main()
{
   const int WIDTH = 7;                  // width of output field

   cout << "Enter:\n\ttotal miles traveled,"
        << "\n\tgallons of fuel used,"
        << "\n\ttotal cost per gallon of the fuel, and"
        << "\n\toperating cost per mile."
        << "\n\t---> ";
   double miles,                         // total miles traveled
          gallonsOfFuel,                 // total gallons used
          unitFuelCost,                  // fuel cost per gallon
          unitOperatingCost;             // operating cost per mile
   cin >> miles >> gallonsOfFuel
       >> unitFuelCost >> unitOperatingCost;

   assert(miles > 0 && gallonsOfFuel > 0 && 
          unitFuelCost > 0 && unitOperatingCost > 0);

   double milesPerGallon = miles / gallonsOfFuel,
          fuelCost = unitFuelCost * gallonsOfFuel,
          operatingCost = unitOperatingCost * miles,
          totalTripCost = fuelCost + operatingCost,
          costPerMile = totalTripCost / miles;

   cout << showpoint << fixed << setprecision(2)
       << "\n\tMiles per gallon: " << setw(WIDTH) << milesPerGallon
       << "\n\tTotal cost:      $" << setw(WIDTH) << totalTripCost
       << "\n\tCost per mile:   $" << setw(WIDTH) << costPerMile
        << endl << endl;

   return 0;
}
