hey everyone..
Im new to this website and I really like it a lot:p I would like to ask you please to help me with the following assignment..
OC Transpo is doing a survey of its service. They have had somebody record the times at which #95 busses pass the Rideau Centre, and need a program which will analyze this data. You are to write a program that reads in times (in hours and minutes on a 24 hour clock) until 99 99 is entered. When this happens your program should output i) the number of times entered, ii) the shortest gap between any two busses, iii) the longest gap between any two busses and iv) the average gap length. The following sample run should give the idea:
Enter time in hours and minutes (99 99 to stop): 10 20
Enter time in hours and minutes (99 99 to stop): 10 31
Enter time in hours and minutes (99 99 to stop): 10 39
Enter time in hours and minutes (99 99 to stop): 99 99
3 times were entered.
The shortest gap was 8 minutes long.
The longest gap was 11 minutes long.
The average gap length was 9.5 minutes.
Times may go past midnight. If a time entered is before 1 0 (1am) and the previous time was after 23 0 (11pm), it should be assumed that times have gone from one day to the next. If an entered time is invalid, your program must output an error message and ignore the time. Hour values must be between 0 and 23 (note: 24 0 is not a valid time), minute values must be between 0 and 59 and, except for the special case described above, times cannot be less than the previously entered time. If you are unclear as to whether something should or should not be accepted, experiment with the sample executable. Note that it makes no sense to output gap information if fewer than two valid bus times have been entered.
Hint 1: It is strongly suggested that you convert times entered to “total minutes past midnight”
before doing any processing.
Hint 2: Begin by writing a program that does not allow times to go past midnight (a somewhat simpler problem). Then, once you have this program working, modify it so that times can go past midnight.
Note: Do NOT use leading zeros when entering times. Values with leading zeroes are assumed to be octal (base eight), and this will create a problem if the following digit is an 8 or a 9.
The code that I did for it is the following:
#include <iostream.h>
#include <math.h>
#include <conio.h>
int main()
{
int hours, minutes, times, sum;
double gap;
hours = 0;
minutes = 0;
sum = 1;
cout <<"Enter time in hours and minutes (99 99 to stop): ";
cin >> hours >> minutes;
while (hours != 99 && minutes != 99)
{
for (hours = 0; hours <= 23; hours++)
{
for (minutes = 0; minutes <= 59; minutes++)
{
cout << sum;
cout << " times were entered. ";
cin >> times;
}
cout << "***ERROR- not a valid time *** \n";
}
break;
}
return 0;
}
the thing that I dont know is how do I actually make the program count the times that I'm entering times and also how do I make it keep on asking me to enter numbers till 99 99?
plzzzzzzzz help me with this :sad: