Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A parking garage charges $2.00 minimum fee to parkfor up to three hours and an a

ID: 3634547 • Letter: A

Question

A parking garage charges $2.00 minimum fee to parkfor up to three hours and an additional $0.50 per hour for each hour or part thereof over three hours. The maximum charge for any givin 24 hour period is $10.00. Assume that no parks for longer than 24 hours at a time. Write a program that will calculate and print the parking charges for eack of three 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:
car hours Charge
1 1.5 2.00
2 4.0 2.50
3 24.0 10.00
total 29.5 14.50

Explanation / Answer

Dear,


//Header file section

#include <stdio.h>
#include <math.h>

/* Declare function prototype */
float calcCharge(float);

/* Initialize main() function */
int main()
{

    /* Declare variables */
    float hours1 = 0.0;
    float hours2 = 0.0;
    float hours3 = 0.0;
    float charge1 = 0.0;
    float charge2 = 0.0;
    float charge3 = 0.0;
    float totalHours = 0.0;
    float totalCharge = 0.0;

    /* Receive input from users. */
    printf("Enter the hours for car 1: ");
    scanf("%f", &hours1);
    printf(" Enter the hours for car 2: ");
    scanf("%f", &hours2);
    printf(" Enter the hours for car 3: ");
    scanf("%f", &hours3);

    /* Calculate total hours */
    totalHours = hours1 + hours2 + hours3;

    /* Calculate charge using the calcCharge() function */
    charge1 = calcCharge(hours1);
    charge2 = calcCharge(hours2) ;
    charge3 = calcCharge(hours3) ;

    /* Calculate total parking charge */
    totalCharge = charge1 + charge2 + charge3;

    /* Display parking charge */
    printf(" Car Hours Charge");
    printf(" 1 %0.1f %0.2f", hours1, charge1);
    printf(" 2 %0.1f %0.2f", hours2, charge2);
    printf(" 3 %0.1f %0.2f", hours3, charge3);
    printf(" Total %0.1f %0.2f ", totalHours, totalCharge);
}

The function calcCharge() calculates the individual charge for each parked car.

/* Define function calcCharge() */
float calcCharge(float hours)
{
    float cHours = ceil(hours);
    float charge = 0.0;

    /* If-else conditions for variable charges */
    if (cHours <= 3.0)
    charge = 2.00;
    else if (cHours > 3.0 && cHours <= 17.0)
    charge = ( ( cHours - 3.0 ) * 0.5 ) + 2.0;
    else
    charge = 10.0;

    return charge;
}

Sample Output:

Enter the hours for car 1:      1.5

Enter the hours for car 2:      4.0

Enter the hours for car 3:      24.0

Car     Hours   Charge
1       1.5     2.00
2       4.0     2.50
3       24.0    10.00
Total   29.5    14.50


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote