//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 = 2;
const int numOfMinsPerHour = 60;
void inputAndValidate(int,int,int,int);
void convertToMinutes(int&,int&,int&,int&);
void convertBackToTime(int&);
double calcCharge(int&,int&,double);
int entranceMinutes,exitMinutes,entranceTimeInMins,exitTimeInMins ;
int minutesParked,parkedMinutes,entranceHour,exitHour,parkedTime ;
int parkedHours;
double charge;
int main()
{
cout<<"Customer"<<setw(10)<<"Entry Time"<<setw(10)<<"Exit Time"<<setw(10)<<"Parked Time"<<setw(10)<<"Charge"<<endl;
for (int num = 1; num <= numOfCustomers; num++ )
{
inputAndValidate(entranceHour,entranceMinutes,exitHour,exitMinutes);
convertToMinutes(entranceHour,entranceMinutes,exitHour,exitMinutes);
convertBackToTime(minutesParked);
cout<<num<<setw(5)<<entranceHour<<"h"<<entranceMinutes<<setw(5)<<exitHour<<"h"
<<exitMinutes<<setw(5)<<parkedTime<<setw(5)<<calcCharge(parkedMinutes,
parkedHours,charge)<<endl;
}
return 0;
}
void inputAndValidate (int entranceHour,int exitHour,int entranceMinutes,int exitMinutes)
{
do{
if(numOfCustomers <= 12)
cout<<"Input the time you entered the garage"<<endl;
cin>>entranceHour >> entranceMinutes;
cout<<"input the time you left the garage"<<endl;
cin>>exitHour >> exitMinutes;
}while((entranceHour>0 && exitHour <= 24) && (entranceMinutes>=0 && exitMinutes <=59));
if(entranceHour == 24)
entranceMinutes = 00;
if(exitHour == 24)
exitMinutes =00;
else
cout<<"Input the valid time"<<endl;
}
void convertToMinutes(int& entranceHour,int& exitHour,int& entranceMinutes,int& exitMinutes)
{
int entraceTimeInMins = (entranceHour * numOfMinsPerHour + entranceMinutes);
int exitTimeInMins = (exitHour * numOfMinsPerHour + exitMinutes);
int minutesParked = (exitMinutes - entranceMinutes);
}
void convertBackToTime(int& minutesParked)
{
int parkedHours = (minutesParked / numOfMinsPerHour);
int parkedMinutes = (minutesParked % numOfMinsPerHour);
int parkedTime = (parkedHours && parkedMinutes);
}
double calcCharge(int& parkedHours ,int& parkedMinutes ,double charge)
{
if ((parkedHours>=3 && parkedHours<=24) && (parkedHours>0 && parkedMinutes<=60)){
int additionalHourMin = (parkedHours - 2);
double charge = (additionalHourMin * hourlyFee + minimumFee);
return charge;
}
else
if((parkedHours>=3 && parkedHours<=24) && (parkedMinutes = 0)){
int additionalHours = (parkedHours - 3);
double charge = (additionalHours * hourlyFee + minimumFee);
return charge;
}
return 0;
}
clyo cleopas 0 Newbie Poster
Edited by TrustyTony because: fixed code formating
VernonDozier 2,218 Posting Expert Featured Poster
Close.
[code]
// paste code here
[/code]
//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 = 2;
const int numOfMinsPerHour = 60;
void inputAndValidate(int,int,int,int);
void convertToMinutes(int&,int&,int&,int&);
void convertBackToTime(int&);
double calcCharge(int&,int&,double);
int entranceMinutes,exitMinutes,entranceTimeInMins,exitTimeInMins ;
int minutesParked,parkedMinutes,entranceHour,exitHour,parkedTime ;
int parkedHours;
double charge;
int main()
{
cout<<"Customer"<<setw(10)<<"Entry Time"<<setw(10)<<"Exit Time"<<setw(10)<<"Parked Time"<<setw(10)<<"Charge"<<endl;
for (int num = 1; num <= numOfCustomers; num++ )
{
inputAndValidate(entranceHour,entranceMinutes,exitHour,exitMinutes);
convertToMinutes(entranceHour,entranceMinutes,exitHour,exitMinutes);
convertBackToTime(minutesParked);
cout<<num<<setw(5)<<entranceHour<<"h"<<entranceMinutes<<setw(5)<<exitHour<<"h"
<<exitMinutes<<setw(5)<<parkedTime<<setw(5)<<calcCharge(parkedMinutes,
parkedHours,charge)<<endl;
}
return 0;
}
void inputAndValidate (int entranceHour,int exitHour,int entranceMinutes,int exitMinutes)
{
do{
if(numOfCustomers <= 12)
cout<<"Input the time you entered the garage"<<endl;
cin>>entranceHour >> entranceMinutes;
cout<<"input the time you left the garage"<<endl;
cin>>exitHour >> exitMinutes;
}while((entranceHour>0 && exitHour <= 24) && (entranceMinutes>=0 && exitMinutes <=59));
if(entranceHour == 24)
entranceMinutes = 00;
if(exitHour == 24)
exitMinutes =00;
else
cout<<"Input the valid time"<<endl;
}
void convertToMinutes(int& entranceHour,int& exitHour,int& entranceMinutes,int& exitMinutes)
{
int entraceTimeInMins = (entranceHour * numOfMinsPerHour + entranceMinutes);
int exitTimeInMins = (exitHour * numOfMinsPerHour + exitMinutes);
int minutesParked = (exitMinutes - entranceMinutes);
}
void convertBackToTime(int& minutesParked)
{
int parkedHours = (minutesParked / numOfMinsPerHour);
int parkedMinutes = (minutesParked % numOfMinsPerHour);
int parkedTime = (parkedHours && parkedMinutes);
}
double calcCharge(int& parkedHours ,int& parkedMinutes ,double charge)
{
if ((parkedHours>=3 && parkedHours<=24) && (parkedHours>0 && parkedMinutes<=60)){
int additionalHourMin = (parkedHours - 2);
double charge = (additionalHourMin * hourlyFee + minimumFee);
return charge;
}
else
if((parkedHours>=3 && parkedHours<=24) && (parkedMinutes = 0)){
int additionalHours = (parkedHours - 3);
double charge = (additionalHours * hourlyFee + minimumFee);
return charge;
}
return 0;
}
Try it again. Mine added the tags, but I can't add the formatting that's already been stripped out.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.