rendered paste body//libraries
#include <iostream>
using namespace std;
#include <iomanip>
using std::setw; //Set a width between columns
using std::setiosflags;
using std::setprecision; //Fixed point decimal
//function prototype
float calculateCharges(float hours);
int main()
{
//hours for each customer
float hours1, hours2, hours3;
//charges for each customer
float charge1, charge2, charge3;
cout << "Enter hours parked for each of three customers.";
cout << "If customer parked for a fractional amount of hours, round up!"
<< setiosflags ( ios::fixed | ios::showpoint );
cin >> hours1 >> hours2 >> hours3;
//stores each person's charges
charge1 = calculateCharges(hours1);
charge2 = calculateCharges(hours2);
charge3 = calculateCharges(hours3);
//spreadsheet-like display of hours and total charges
cout << " Car" << setw ( 10 ) << "Hours" << setw ( 10 ) << "Charge" <<endl;
cout << " 1" << setw ( 10 ) << setprecision ( 2 ) /*fixes decimal to two places*/ << hours1 << setw ( 10 ) << setprecision ( 2 ) << charge1 <<endl;
cout << " 2" << setw ( 10 ) << setprecision ( 2 ) << hours2 << setw ( 10 ) << setprecision ( 2 ) << charge2 <<endl;
cout << " 3" << setw ( 10 ) << setprecision ( 2 ) << hours3 << setw ( 10 ) << setprecision ( 2 ) << charge3 <<endl;
cout << "Total" << setw ( 10 ) << setprecision ( 2 ) << hours1 + hours2 + hours3 << setw ( 10 ) << setprecision ( 2 ) << charge1 + charge2 + charge3 <<endl;
return 0;
}
//function that calculates and returns charges
float calculateCharges(float hours)
{
if (hours <= 3) //Fee of $2.00 if 3 or fewer hours
{
return 2;
}
if (hours > 3 && hours <= 19) //Add $.50 per hour up to $10.00
{
return 2 + (.5 * (hours - 3));
}
if (hours > 19) //Maximum $10.00
{
return 10;
}
return 0;
}