// File: prog1_1.cpp
// the program uses Time24 objects to compute the cost of
// parking a car in a public garage at the rate is $6.00 per hour.
// after the user inputs the times at which a customer enters and
// exits the garage, the program outputs a receipt that includes
// the enter and exit times, the length of time the car is parked
// and the total charges

#include <iostream>

#include "simpletime24v2.h"

using namespace std;

int main()
{
   // cost of parking per hour
   const double PERHOUR_PARKING = 6.00;

   Time24 enterGarage,   // when a car enters the garage
          exitGarage,    // when a car leaves the garage
          parkingTime;   // total amount of parking time
   double billingHours;  // length of billing time in hours
   bool   success;       // flag for Duration call


   cout << "Enter the time the car enters the garage: ";
   enterGarage.ReadTime(cin);
   cout << "Enter the time the car exits the garage: ";
   exitGarage.ReadTime(cin);

   // compute the total parking time
   parkingTime =  enterGarage.Duration(exitGarage, success);

   if (success)
   {
      // compute the parking time in hours
      billingHours = parkingTime.GetHour() + parkingTime.GetMinute()/60.0;
      
      // output parking receipt including time of arrival, time
      // of departure, total parking time, and cost of parking
      cout << "\nCar enters at: ";
      enterGarage.WriteTime(cout);
      cout << endl;
      
      cout << "Car exits at: ";
      exitGarage.WriteTime(cout);
      cout << endl;
      
      cout << "Parking time: ";
      parkingTime.WriteTime(cout);
      cout << endl;

      cout.setf(ios::fixed|ios::showpoint);
      cout.precision(2);
      cout << "Cost is $" << billingHours * PERHOUR_PARKING  << endl;
   }
   else
      cerr << "Time24 Duration(): argument an earlier time\n";

   return 0;
}  // end main
