HI, I'm new at this so I just need a little bit of assistance in this. I have done the source code and everything for this problem but can't do 1 thing. I need the program to end when I type 99 hours. Below is the problem and source code. I would appreciate anyone's help. thanks.
A parking garage charges a $2.00 minimum fee to park for up to 3 hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of 3 hours. The maximum charge is $10.00. (Hint: That means you dont have to calculate for anything over 18 hours.) Write a program that calculates and prints the parking charges for a number of cars. The user will enter the number of hours in hours and tenths of an hour. For example, the user will enter 4.5 for 4 hours and 30 minutes. The user will enter 99 hours to signal that the program should end.
Code:#include <stdio.h> int main() { int car[3]; double hours[3], total_hours = 0; double charge[3], total_charge = 0; int i; for ( i = 0; i < 3; ++i ) //car[i]=0; { printf("Enter car number? "); scanf("%d", &car[i]); printf("Enter hours parked? "); scanf("%lf", &hours[i]); if ( hours[i] < 3 ) { charge[i] = 2.0; } else if ( hours[i] < 18 ) { charge[i] = 2.0 + (hours[i] - 3.0) * 0.50; } else { charge[i] = 10.0; } //printf("%1f%1f\n", "car" "hours" "charge"); //for (car=1; car < 3; ++car) { //printf("%d%1f%1f\n", car,hours,charge[hours]); //printf("%.2f%.2f\n", total_hours[hours],total_charge[charge]); total_hours = total_hours + hours[i]; total_charge = total_charge + charge[i]; } printf("%s %s %s\n", "car", "hours", "charge"); for (i=0; i < 3; ++i) { printf("%d %.1f %.2f\n", car[i], hours[i], charge[i]); } printf(" %.2f %.2f\n", total_hours/*[hours]*/,total_charge/*[charge]*/); return 0; }



LinkBack URL
About LinkBacks


