A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car is parks for longer than 24 hours at a time. Write a program that will calculate and print the parking charges for each of 3 customers who parked their cars in this garage yesterday. You should enter the hours parked for eached customer. Your program should print the results in a tabular format and slould calculate and print the total of yesterday's receipts. The program should have a function named calculateCharges to determine the charge for each customer. Your outputs should appear in the following format: I don't know what I'm doing wrong.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
using std::cout;
using std::endl;
using std::cin;
using std::setw;
double calculateCharges( double );
int main() {
double charge = 0;
double hours = 0;
double total;
double cars;
double car1, car2, car3;
cout << "Enter Hours for Car1: " << car1 << endl;
cin >> car1;
cout << "Enter Hours for Car2: " << car2 << endl;
cin >> car2;
cout << "Enter Hours for Car3: " << car3 << endl;
cin >> car3;
cout << "Charge Car1: " << car1 << endl;
cout << "Charge Car2: " << car2 << endl;
cout << "Charge Car3: " << car3 << endl;
cout << "Cars" << setw( 13 ) << "Hours" << setw( 13 ) << "Charge" << endl;
cout << " 1" << setw( 13 ) << car1 << endl;
cout << " 2" << setw( 13 ) << car2 << endl;
cout << " 3" << setw( 13 ) << car3 << endl;
return 0;
}
double calculateCharges( double ){
double hours = 3, charge = 2.00;
if (hours <= 3)
charge = 2.00;
else if (hours >= 24)
charge = 2.50;
else
charge = 10.00;
return charge;
}
Note
#######
The program is updated. Function to calculate parking charge was wrong. Please go through the code
//##################### PGM START ##################
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
using std::cout;
using std::endl;
using std::cin;
using std::setw;
double calculateCharges( double );
int main() {
double total;
double car1, car2, car3;
cout << "Enter Hours for Car1: ";
cin >> car1;
cout << "Enter Hours for Car2: ";
cin >> car2;
cout << "Enter Hours for Car3: ";
cin >> car3;
total=calculateCharges(car1)+calculateCharges(car2)+calculateCharges(car3);
cout << "Cars" << setw( 13 ) <<
"Hours" << setw( 13 ) << "Charge($)" <<
endl;
cout << " 1" << setw( 13 )
<< car1 << setw( 13 ) <<
calculateCharges(car1)<<endl;
cout << " 2" << setw( 13 )
<< car2 << setw( 13 ) <<
calculateCharges(car2)<<endl;
cout << " 3" << setw( 13 )
<< car3 << setw( 13 ) <<
calculateCharges(car3)<<endl;
cout<<"\nTotal Parking Charge:
"<<setw(8)<<total<<"\n";
return 0;
}
//function to claculate parking charge was wrong
double calculateCharges( double hours ){
double charge = 2.00;
if (hours <= 3)
charge = 2.00;
else if (hours >= 24)
charge = 10;
else
charge+=((hours-3)*0.5);
return charge;
}
//############################# PGM END
##########################
OUTPUT
#########
Get Answers For Free
Most questions answered within 1 hours.