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;
}``````

## All 7 Replies

And what seems to be the problem and where is it in your code?

I am trying to have the program to print a summery for the user at the end of the day that includes the number of cars, number of trucks, number of seniors, total costs, and total time of the vehicles. I cannot seem to get the counters to work at the end of the program, though they may be working and I just do not know about it..I cannot exit the program either at the end of the day.

``````while (1){

}
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;
}``````

I alsto tried

``while (op != EOF)``

do it like this

``````do{
printf("do you want to exit(y/n)");
char a=getchar()

}while(a!='y'||a!='Y');``````

The issue is that I need to end the program when "control Z" is typed by the user, and then print

``````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);``````

.

The issue is that I need to end the program when "control Z" is typed by the user...

Read up on the `scanf()` function and see if it returns a value. That may give you a major clue on what to do.

Control+Z (aka ^Z), is the end of file indicator, for DOS and Windows (all versions). It is an integer, and can't be detected as a char. So there's your while (or for) loop:

``````while(first integer != EOF) {