The program runs but the math is not correct ( output for amount )
#include <iostream>
using namespace std;
int main()
{
int hoursParked;
double total;
double Car = 2.50 ;
double Truck = 5.50;
double Bus = 19.00;
double rateC = 1.50;
double rateT = 3.75;
double rateB = 6.75;
char type;
cout << "Please Enter number of hours parked and the type of
car (Type: (C)ar or (T)ruck or (B)us): " << endl;
cin >> type >> hoursParked;
switch (type)
{
case 'C':
case 'c':
{
if (hoursParked <= 2.00)
total = 2 * 1.25;
else
total = (( hoursParked - 2.00 )* rateC)+ Car ;
}
case 'T':
case 't':
{
if (hoursParked <= 2.00)
total = Truck;
else
total = ((hoursParked - 2.00) * rateT) + Truck;
break;
}
case 'B':
case 'b':
{
if (hoursParked <= 2.00)
total = Bus;
else
total = ((hoursParked - 2.00)*rateB) + Bus;
break;
}
}
cout << "Vehicle type: ";
if(type == 'C')
cout << "Car" << endl;
else if(type == 'T')
cout << "Truck" << endl;
else
cout << "Bus" << endl;
cout << "Time:" << hoursParked << endl;
cout << "Amount Due:$" << total <<endl;
return 0;
}
I made slight changes to your program so that it will perform accurately. You have not given any input conditions, so that I have taken like parking charges are made minimum for 2 hours. The program had compiled and running accordingly
#include <iostream>
using namespace std;
int main()
{
int hoursParked;
double total;
double Car = 2.50 ;
double Truck = 5.50;
double Bus = 19.00;
double rateC = 1.50;
double rateT = 3.75;
double rateB = 6.75;
char type;
cout << "Please Enter number of hours parked and the type
of car (Type: (C)ar or (T)ruck or (B)us): " << endl;
cin >> type >> hoursParked;
switch (type)
{
case 'C':
case 'c':
{
if (hoursParked <= 2.00){
total = 2 * 1.25;
}
else{
total = (( hoursParked - 2.00 )* rateC)+ Car ;
}
cout << "Vehicle type: " << "Car"<<endl <<
"Time:" << hoursParked <<endl <<"Parking Charges
$"<<total<<endl;
break;
}
case 'T':
case 't':
{
if (hoursParked <= 2.00)
total = Truck;
else
total = ((hoursParked - 2.00) * rateT) + Truck;
cout << "Vehicle type: " << "Truck "<<endl
<< "Time:" << hoursParked <<endl <<"Parking
Charges $"<<total<<endl;
break;
}
case 'B':
case 'b':
{
if (hoursParked <= 2.00)
total = Bus;
else
total = ((hoursParked - 2.00)*rateB) + Bus;
cout << "Vehicle type: " << "Bus "<<endl <<
"Time:" << hoursParked <<endl <<"Parking Charges
$"<<total<<endl;
break;
}
}
return 0;
}
Output:
Get Answers For Free
Most questions answered within 1 hours.