Answer to Question #174941 in C++ for Pali

Question #174941

A parking garage charges a R12.00 minimum fee to park for up to three hours. The garage charges an additional R0.90 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is R20.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. Your outputs should appear in the following format


1
Expert's answer
2021-03-24T03:02:40-0400
#include <iostream>
using namespace std;

float calculateCharges(int hours) {
    // minimal charge is 12
    float charge = 12;
    // + 0.90 for every hour excess of three
    if (hours > 3) charge += (hours - 3) * 0.90;
    // maximum charge is 20
    if (charge > 20) charge = 20;
    return charge;
}

int main() {
    int hours1;
    cout << "Enter parking hours for the first customer:";
    cin >> hours1;
    float charge1 = calculateCharges(hours1);

    int hours2;
    cout << "Enter parking hours for the second customer:";
    cin >> hours2;
    float charge2 = calculateCharges(hours2);

    int hours3;
    cout << "Enter parking hours for the third customer:";
    cin >> hours3;
    float charge3 = calculateCharges(hours3);

    cout << endl << endl;
    cout << "first \t\tsecond \t\tthird" << endl;
    cout << charge1 << "\t\t" << charge2 <<"\t\t" << charge3 << endl;

    float total = charge1 + charge2 + charge3;
    cout << "Total charge: " << total;
}

The answer should be given in some specific format, that was not provided. Please check the output and fix it as needed.


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
APPROVED BY CLIENTS