0

```
//A c++ program that calculate and print parking charges
#include <iostream>
using namespace std;
#include <iomanip>
const double minimumFee = 7.00;
const double hourlyFee = 1.75;
const int numOfCustomers = 12;
const int numOfMinsPerHour = 60;
void inputAndValidate(int&,int&,int&,int&);
void convertToMinutes(int&,int&,int&,int&);
void convertBackToTime(int&,int&,int&);
double calcCharge(int,int);
int entranceMinutes,exitMinutes,entranceTimeInMins,exitTimeInMins ;
int minutesParked,parkedMinutes,entranceHour,exitHour,parkedTime ;
int parkedHours,numb;
int count =1;
int main()
{
cout<<"\nWELCOME TO MANAMELA'S PARKING GARAGE"<<endl;
cout<<"**************************************\n";
for (int num = 1; num <= numOfCustomers; num++ )
{
while(count <=12){
inputAndValidate(entranceHour,entranceMinutes,exitHour,exitMinutes);
convertToMinutes(entranceHour,entranceMinutes,exitHour,exitMinutes);
convertBackToTime(minutesParked,parkedHours,parkedMinutes);
cout<<"Customer#"<<setw(10)<<"EntryTime"<<setw(10)<<"ExitTime"
<<setw(10)<<"\tParkedTime"<<setw(10)<<"Charge"<<endl;
cout<<"\n"<<num<<setw(10)<<entranceHour<<"h"<<entranceMinutes<<setw(10)
<<exitHour<<"h"<<exitMinutes<<setw(10)<<parkedHours<<"h"
<<parkedMinutes<<setw(15)<<calcCharge(parkedMinutes,
parkedHours)<<endl;
count++;
}
}
return 0;
}
void inputAndValidate (int& entranceHour,int& entranceMinutes,int& exitHour,int& exitMinutes)
{
int invalid =1 ;
while(invalid ==1){
invalid++;
cout<<"\nEnter entrance time in hours and minutes\n";
cin>>entranceHour>>entranceMinutes ;
cout<<"\nEnter exit time in hours and minutes\n";
cin>>exitHour>>exitMinutes;
if(entranceHour == 24)
entranceMinutes = 00;
if(exitHour ==24)
exitMinutes = 00;
if(entranceHour<0 || entranceHour >25 ||entranceMinutes<0 || entranceMinutes>=59 ||
exitHour<0 || exitHour>25 || exitMinutes <0 || exitMinutes>=59 ){
cout<<"Invalid time.Try again:\n";
invalid-- ;
count --;
}
}
}
void convertToMinutes(int& entranceHour,int& entranceMinutes,int& exitHour,int& exitMinutes)
{
entranceTimeInMins = (entranceHour * numOfMinsPerHour + entranceMinutes);
exitTimeInMins = (exitHour * numOfMinsPerHour + exitMinutes);
minutesParked = (exitTimeInMins - entranceTimeInMins);
}
void convertBackToTime(int& minutesParked,int& parkedHours,int& parkedMinutes)
{
parkedHours = (minutesParked / numOfMinsPerHour);
parkedMinutes = (minutesParked % numOfMinsPerHour);
}
double calcCharge(int parkedHours ,int parkedMinutes)
{
double charge;
if (parkedHours>=3 && parkedHours<=24 && parkedMinutes>0 && parkedMinutes<=59)
{
int additionalHourMin = (parkedHours - 2);
charge = (additionalHourMin * hourlyFee + minimumFee);
return charge;}
else
if(parkedHours>=3 && parkedHours<=24 && parkedMinutes == 0){
int additionalHours = (parkedHours - 3);
charge = (additionalHours * hourlyFee + minimumFee);
return charge;}
else
if(parkedHours>0 && parkedHours<3 && parkedMinutes>=0 && parkedMinutes<=59){
charge = minimumFee;
return charge;}
return 0;
}
```

I think my calculation are correct according to problem statement"A parking garage charges a R7.00 minimum fee to park for up to three hours. The garage charges an additional R1.75 per hour or part thereof in excess of three hours".I misunderstand the results.