64 747
Assignments Done
99,3%
Successfully Done
In September 2018

# Answer to Question #55374 in C++ for Shaptu

Question #55374
A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional$0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour 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 tabular 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. Expert's answer Solve #include <stdio.h> #define NUM 3 using namespace std; float calculateCharges (int hours) { if(hours<=3) return 2; else { float pay; pay=0.5*(hours-3)+2; if(pay>10) return 10; else return pay; } } int main() { float pay[NUM]; int hours[NUM]; int i; for(i=0;i<NUM;i++) { printf("Input hours for customer #%d: ",i+1); scanf("%d",&hours[i]); } float sum=0; printf("\n# | hours | payment"); for(i=0;i<NUM;i++) { pay[i]=calculateCharges (hours[i]); printf("\n%3d| %5d |$%7.2f",i+1,hours[i],pay[i]);
sum+=pay[i];
}
printf("\nTotal of yesterday's receipts: \$%5.2f",sum);
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!