I have been ok so far but now I am having a problem with counting the amount of time that cars spend in the lot during the day and counting the total cost at the end of the day. Any pointers in the right direction would be helpful. Here are the guidelines of the assignment.
Cars:
0-2 First 2 hours Free
2-5 Next 3 hours 0.50/hour
5-15 Next 10 hours .25/hour
Trucks:
0-1 First 1 hour Free
1-3 Next 2 hours 1.00/hours
3-15 Next 12 hours 0.75/hour
Senior Citizens: Free of charge
Write a program that will accept as input a one-character designator (C, T or S)
Followed by two military numbers in range of 0600-2200 (6:00 A.M to 10:00 P.M). The program should
Then compute the appropriate charge and the round up time that car was parked.
The output should be printed for each vehicle, arrival time, departure time and cost. Your program should also provide a summery at the end of each day indicating total cars, trucks, and senior, time and fees. Your program should have loop which ends with ^Z.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int timea, timed, time1;
double numcar = 0.0, numtruck = 0.0, numsenior = 0.0, cost = 0.0, numtime = 0.0;
char group;
while (1) {
printf("C- car, T- truck, S- Senior Citizens.\n");
printf("Please enter all times in military format in range 0600-2200.\n");
scanf("%c", &group);
printf(" What time did you arrive?\n");
scanf("%d", &timea);
printf(" What time are you leaving?\n");
scanf("%d", &timed);
time1 = timed - timea;
switch (group){
case 'C': {numcar++;
if (time1 > 200)
cost = ((time1 - 200)/100) * 0.5;
if (time1 > 500)
cost = 1.5 + ((time1 - 500)/100) * 0.25;
printf("Arrival Time: %d, Departure Time: %d, Cost: %lf.\n", timea, timed, cost );
getchar();
}
break;
case 'T': {numtruck++;
if (time1 > 100) {
cost = ((time1 - 100)/100) * 1;
}
if (time1 > 300) {
cost = 2 + ((time1 - 300)/100) * 0.75;
}
printf("Arrival Time: %d, Departure Time: %d, Cost: %lf.\n", timea, timed, cost );
getchar();
}
break;
case 'S': {numsenior++;
printf("Arrival Time: %d, Departure Time: %d, Cost: %lf.\n", timea, timed, cost );
getchar();
}
break;
}
}
printf("Summary of Parking Lot Today.\n");
printf("Number of Cars: %lf\n", numcar);
printf("Number of Trucks: %lf\n", numtruck);
printf("Number of Seniors: %lf.\n", numsenior);
printf("Total time of cars in lot: %lf\n", numtime);
printf("Total fees collected: %lf\n", cost);
return 0;
}