1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include<iostream>
using namespace std;
int InputAndValidate(int entranceHourP,int entranceMinutesP,int extHourP,int exitMinutesP)
{
cout<<"Enter your entrance hour: ";
cin>>entranceHourP;
while(entranceHourP>24 ||entranceHourP<0)
{
cout<<"Your hour can not be more than 24hrs or less than 0hrs!"<<endl;
cout<<"Try and enter the correct time!"<<endl;
cout<<"Enter your entrance hour: ";
cin>>entranceHourP;
}
cout<<"Enter your entrance munites: ";
cin>>entranceMinutesP;
while(entranceMinutesP>59 || entranceMinutesP<0)
{
cout<<"Your hour can not be more than 60mins or less than 0mins!"<<endl;
cout<<"Try and enter the correct time!"<<endl;
cout<<"Enter your entrance munites: ";
cin>>entranceMinutesP;
}
cout<<"Enter your Exit hour: ";
cin>>extHourP;
while(extHourP>24 ||extHourP<0)
{
cout<<"Your hour can not be more than 24hrs or less than 0hrs!"<<endl;
cout<<"Try and enter the correct time!"<<endl;
cout<<"Enter your Exit hour: ";
cin>>extHourP;
}
cout<<"Enter your Exit munites: ";
cin>>exitMinutesP;
while(exitMinutesP>60 || exitMinutesP<0)
{
cout<<"Your hour can not be more than 60mins or less than 0mins!"<<endl;
cout<<"Try and enter the correct time!"<<endl;
cout<<"Enter your Exit munites: ";
cin>>exitMinutesP;
}
return entranceHourP, entranceMinutesP, extHourP, exitMinutesP;
}
int ConvertToMinutes(int entranceHourP,int entranceMinutesP,int extHourP,int exitMinutesP,int &EntranceTimeInMinsP, int &ExitTimeInMinsP,int &minutesParkedP)
{
EntranceTimeInMinsP=((entranceHourP*60)+entranceMinutesP);
cout<<"Entrance Time In Mins: "<<EntranceTimeInMinsP<<endl;
ExitTimeInMinsP=((extHourP*60)+ exitMinutesP);
cout<<"Exit Time In Mins: "<<ExitTimeInMinsP<<endl;
minutesParkedP=ExitTimeInMinsP-EntranceTimeInMinsP;
cout<<" Time parked in minutes Parked: "<<minutesParkedP<<endl;
return minutesParkedP;
}
int ConvertBactToTime(int minutesParkedP,int &parkedHoursP,int &parkedMinutesP)
{
parkedHoursP=minutesParkedP/60;
cout<<"Parked hours is : "<<parkedHoursP<<endl;
parkedMinutesP= (parkedHoursP%60);
cout<<"parked Minutes: "<<parkedMinutesP<<endl;
return parkedHoursP,parkedMinutesP;
}
float CalcCharge(int parkedHoursP,int parkedMinutesP, float &chargeP, float &totalChargeP)
{
if (parkedHoursP<3)
chargeP=7;
else
for(int r=4; r<=parkedHoursP;r++)
{
chargeP=(chargeP +1.50);
}
totalChargeP=chargeP;
cout<<"Total charge for: "<<parkedHoursP<<"h"<<parkedMinutesP<<" is: R"<<totalChargeP<<endl;
return chargeP, totalChargeP;
}
main()
{
int entranceHour,entranceMinutes;
int extHour,exitMinutes;
int EntranceTimeInMins,ExitTimeInMins,minutesParked;
int parkedHours,parkedMinutes;
float charge, totalCharge;
for (int i=1;i<=10;i++)
{
InputAndValidate(entranceHour,entranceMinutes,extHour,exitMinutes);
ConvertToMinutes(entranceHour,entranceMinutes,extHour,exitMinutes,EntranceTimeInMins,ExitTimeInMins,minutesParked);
ConvertBactToTime(minutesParked,parkedHours,parkedMinutes);
CalcCharge(parkedHours,parkedMinutes,charge,totalCharge);
}
system("pause");
}
| |