149k views
0 votes
A parking garage charges a $20.00 minimum fee to park for up to three hours. The garage charges an additional $5.00 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $50.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charges for each of the three customers who parked their cars in this garage today. 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. You should create a function named calculateCharges to determine the charge for each customer.

float calculateCharges( float hours );

Here is the code to get you started with formatting the header:



I've got a fully functional program and everything works except for my math for a charge that's over 20 and under 50. Its supposed to calculate for the whole hour so 5.3 hours would be charged as 5 hours but mine is charging 5.3 and I'm not getting a .00 answer as instructed. -- Attached a photo of what I have and what its supposed to be.

TIA

A parking garage charges a $20.00 minimum fee to park for up to three hours. The garage-example-1
A parking garage charges a $20.00 minimum fee to park for up to three hours. The garage-example-1
A parking garage charges a $20.00 minimum fee to park for up to three hours. The garage-example-2
User Artium
by
8.2k points

1 Answer

4 votes

Answer:

hope this helps!

Step-by-step explanation:

#include <stdio.h>

// Function to calculate charges

float calculateCharges(float hours) {

float minFee = 20.00;

float charge;

if (hours <= 3.0) {

charge = minFee;

} else if (hours > 3.0 && hours < 8.0) {

charge = (hours - 3) * 5 + minFee;

} else {

charge = 50.00;

}

return charge;

}

int main() {

float chargeOne, chargeTwo, chargeThree, hoursOne, hoursTwo, hoursThree, totalHours, totalCharge;

printf("Enter the number of hours for the first customer: ");

scanf("%f", &hoursOne);

chargeOne = calculateCharges(hoursOne);

printf("Enter the number of hours for the second customer: ");

scanf("%f", &hoursTwo);

chargeTwo = calculateCharges(hoursTwo);

printf("Enter the number of hours for the third customer: ");

scanf("%f", &hoursThree);

chargeThree = calculateCharges(hoursThree);

printf("\\Car\tHours\tCharge\\");

printf("1\t%.1f\t$%.2f\\", hoursOne, chargeOne);

printf("2\t%.1f\t$%.2f\\", hoursTwo, chargeTwo);

printf("3\t%.1f\t$%.2f\\", hoursThree, chargeThree);

totalHours = hoursOne + hoursTwo + hoursThree;

totalCharge = chargeOne + chargeTwo + chargeThree;

printf("\\Total\t%.1f\t$%.2f\\", totalHours, totalCharge);

return 0;

}

User Sebthemonster
by
8.5k points