Exercise 3: A car park charges a £2.00
minimum fee to park for up to 3 hours, and an additional £0.50 for each hour or
part hour in excess of three hours. The maximum charge for any given 24-hour
period is £10.00. Assume that no car parks for more than 24 hours at a time.
Write a C
program that will calculate and print the parking charges for each of 3
customers who parked their car in the car park yesterday. The program should
accept as input the number of hours that each customer was parked, and output
the results in a neat tabular form, along with the total receipts from the
three customers:
The program should use the
function calculate_charges to determine the charge for each customer.
void line()
{
int i;
printf("\n");
for(i=1;i<=35;i++)
printf("=");
}
void header()
{
printf("\n");
printf("Built and Designed by Arslan-ud-Din-Shafiq\n\nReg. No .DDP-SP14-BSE-005");
printf("\n");
}
float a(float hours,float charge)
{
if(hours==0)
return 0;
if(hours<=3)
return charge=2;
else if (hours>3 && hours <19)
return charge=2+(0.5*(hours-3));
else if (hours>=19 && hours<=24)
return charge=10;
}
int main()
{
int car=1;
float hrs,chrg,sum1,sum2;
line();
header();
line();
printf("\nCar\tHours\tCharge");
while(car!=4)
{
printf("\t\t\n\n\t");
scanf("%f",&hrs);
printf("%d\t\t%.2f",car,a(hrs,chrg));
car++;
sum1+=hrs;
sum2+=a(hrs,chrg);
}
printf("\n\nTotal\t%.2f\t%.2f\n\n\n\n",sum1,sum2);
return 0;
}
You may be interested in reading more tutorials on Learn Cybers.
Also you can enjoy GTA 5 Cheats PS4.
very nice. thanks
ReplyDelete