A parking garage charges a $2.00 minimum fee to park for up to 3 hrs. The garag charges an additional .50c per hour for each hour or any part of an hour in excess of 3 hrs. the maximum charge for any given 24 hr period is $10. Assume that no car parks for longer than 24 hours at a time. write a program that will calculate and print the parking charger for each of 8 customers who parked their cars in the garage yesterday. you should enter the hours parked for each customer. The program should print the results in a table and should calculate and print the total of yesterdays receipt. write and use a function named calculateCharges to determine the charge for each customer. The function should accept the number of hrs that a customers vehicle was parked and return the amount owed by the customer.
Im not sure exactly how to make my table work
this is what i have so far
Code:#include <stdio.h> #include <math.h> float calculateCharges(float); const int NUMBER_OF_CARS= 8; main() { int cars[NUMBER_OF_CARS]= {1,2,3,4,5,6,7,8}; float charges[NUMBER_OF_CARS]; int i; float hours= 0.0; float charge= 0.0; float totalHours= 0.0; float totalCharges= 0.0; for(i=0; i<NUMBER_OF_CARS; i++) { printf("Enter the hours for car %d:\n", cars[i]); scanf("%.1f",&hours); totalHours = totalHours + cars[i]; charge[i] = calculateCharges[i]; totalCharges = totalCharges + charge[i] printf("\n"); printf("Car\t\t\Hours\t\t\Charge\n"); printf("[i]\t\t\%.1f\t\t\%.2\n", totalHours[i], totalCharges[i]); } printf("TOTAL\t\t\%.1f\t\t\%.2f", totalHours, total Charges); float calculateCharges(float h) { const float MINIMUM_CHARGE = 2.0; const float MAXIMUM_CHARGE = 10.00; /* the garage charges 2.00 for any amount of time up to 3 hours */ if (h<=3) return MINIMUM_CHARGE; /* determine how many hours past 3 hours */ h = h - 3; /* 0.50 for each hour (or part of an hour) past 3 hours */ float additionalAmount = ceil(h) * 0.50; float charge = MINIMUM_CHARGE + additionalAmount; if (charge > MAXIMUM_CHARGE) return MAXIMUM_CHARGE; /* determine how many hours past 3 hours */ h = h - 3; /* 0.50 for each hour (or part of an hour) past 3 hours */ float additionalAmount = ceil(h) * 0.50; float charge = MINIMUM_CHARGE + additionalAmount; if (charge > MAXIMUM_CHARGE) return MAXIMUM_CHARGE; else return charge; }



LinkBack URL
About LinkBacks


