202k views
0 votes
A parking garage charges a $2.00 minimum fee to park for up to 3 hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of 3 hours. The maximum charge for any given 24-hou 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 tubular 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 output should appear in the following format:

Output:

Enter the hours parked for 3 cars:

1.5 4.0 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
#include
#include
Float calculateCharges(float);
main()
{
}
Float calculateCharges(float hours)
{
}

User Rasheena
by
5.0k points

1 Answer

1 vote

Answer:

#include <stdio.h>

#include <math.h>

float calculateCharges(float);

int main()

{

float cust[3],charge[3],totc=0,toth=0;

int i;

printf("Enter the hours parked for 3 cars:\\");

for(i=0;i<3;i++)

{

scanf("%f",&cust[i]);

charge[i]=calculateCharges(cust[i]);

toth+=cust[i];

totc+=charge[i];

}

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

for(i=0;i<3;i++)

{

printf("%d\t%0.1f\t%0.2f\\",i+1,cust[i],charge[i]);;

}

printf("Total\t%.1f\t%.2f\\",toth,totc);

}

float calculateCharges(float hours)

{

float charge;

if(hours>3)

{

if(hours>=19)

{

charge=10;

}

else

{

charge=2+ceil(hours-3)*0.5;

}

}

else

{

charge=2;

}

return charge;

}

Step-by-step explanation:

  • Prompt the user to enter the number of hours parked.
  • Call the function calculateCharges().
  • Calculate the total number of hours of all cars parked.
  • Calculate the total charge of all cars parked.
  • Print the charges for parking along with number of hours and serial number of the car.
  • Calculate the charges if the number of hours is greater than 3 and less than 19.
User Icespace
by
6.3k points