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.