Answer to Question #319338 in C++ for Alexis

Question #319338

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 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 each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday's receipts. The program should use the function calculateCharges to determine the charge for each customer.


1
Expert's answer
2022-03-28T02:29:34-0400
#include <iostream>
#include <iomanip>
using namespace std;

double calculateChargees(double hours) {
    double charges = 2.0;

    int iHours = static_cast<int>(hours +0.99);
    charges += 0.5 * (iHours - 3);
    if (charges > 10.0) {
        charges = 10.0;
    }

    return charges;
}


int main() {
    double hours[3];
    double charges[3], total=0.0;

    for (int i=0; i<3; i++) {
        cout << "Enter parking time for the customer " << i+1 << ": ";
        cin >> hours[i];
        charges[i] = calculateChargees(hours[i]);
        total += charges[i];
    }
    cout << endl;
    cout << "Cust # | Hours | Charge" << endl;
    cout << "-------+-------+-------" << endl;
    for (int i=0; i<3; i++) {
        cout << setw(6) << i+1 << " | ";
        cout << fixed << setprecision(2) << setw(5) << hours[i] << " | ";
        cout << "$" << setw(5) << charges[i] << endl;
    }
    cout << "-------+-------+-------" << endl;
    cout << " Total charges   $" << setw(5) << total << endl;

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog