// 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 <cstdlib>          // exit()
#include "except.h"         // RangeError
#include "simpletime24.h"   // Time24

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   done = false;  // successfully read input data

   while (!done)
   {
      try
      {
	 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);
	 done = true;
      }  // end try
      catch (const RangeError & re)
      {
	 cerr << re.What() << endl;
	 cerr << "Please enter your data again\n\n";
      }  // end catch
   }  // end while
      

   // 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;

   return 0;
}  // end main
