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:\n");
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\n");
for(i=0;i<3;i++)
{
printf("%d\t%0.1f\t%0.2f\n",i+1,cust[i],charge[i]);;
}
printf("Total\t%.1f\t%.2f\n",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;
}
Explanation: