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:

I'm not going to give the full solution to you - but here's some pseducode which may help you better understand what you need to do:

do
    ask for input
    store input
    increment times
while (99 99 hasn't been entered)

process data
print out results

The only thing I'm not sure of what you want to do is the storing of the data. You could use static arrays, although that limit the amount of data you could store, plus it would be a waste of memory. Personally I would use vectors or linked lists, but if you don't have experience using these, I would recommend against it and stick with arrays for now.

Hope this helps

PS. Why do you leave assignments to the last day? If you came earlier it wouldn't be so urgent!

hii, sorry im new to this website and I actually registered in here today, so that is why I asked today cause while I was searching for something helpfull on the internet..I found about this website..plzzz forgive me for asking too late.. but i really didnt mean to do that..ok what i did, is i followed what you told me and i did the following:

#include <iostream.h>
#include <math.h>
#include <conio.h> 
int main(void)
{
 int hours, minutes, times;
 double gap, length;
 hours = 0;
 minutes = 0;
 times = 1;
 do
 {
  cout <<"Enter time in hours and minutes (99 99 to stop): ";
  cin >> hours >> minutes;
  continue;
  cout << times++;
  cout << " times were entered. ";
  cin >> times;
 } 
 while (hours != 99 && minutes != 99);
  
 
  for (hours = 0; hours <= 23; hours++)
  {
   for (minutes = 0; minutes <= 59; minutes++)
   {
    cout << "The shortest gap was " << gap << " minutes long. ";
    cout << "The longest gap was " << gap << " minutes long. ";
    cout << "The average gap length was " << length << " minutes. ";
   }
   cout << "***ERROR- not a valid time *** \n";
  }
 }

but still this is not working the way i want to and you are writting to me with a code that I kind of dont understand cause I know in C++ only..like what should i do after the while loop condition and how do actually calculate the gaps in between them?? im confused a bit plzzz
Thanks

Several things:

  • Please use code tags. There's more information in my signature.
  • Don't use iostream.h and math.h as they're outdated. The modern replacement is this:
    #include <iostream>
    #include <cmath>
    using namespace std;

    Just so you know, there's also no need for conio.h.

  • You aren't actually storing the different values, which is where your problem lies. Each time you use cin >>, you just overwrite the previous data. Like I said before, there are multiple ways of storing the data, but probably the easiest one for you is to use arrays.
  • What is this line supposed to do?
    cin >> times;

the line

cin >> times;

is just to print out the number of times the user enters the times!!

the line

cin >> times;

is just to print out the number of times the user enters the times!!

Hmm... I think you got it backwards ;)

cout << times << endl;

oh god..plzzzzzzz i hate this..i just cant find how to make the program counts how many times im entering numbers

make a varible and increment it by one every time it goes through the loop

yes i will give u points as much as u want plzzz, but just help me

something like (i dont know c++ so this is kinda psudocode)

loop until (input = 9999)

//code goes here

times = times + 1

Do

and so every time it goes through the loop the varriable called tmes is incremented by 1

oh god..plzzzzzzz i hate this..i just cant find how to make the program counts how many times im entering numbers

In your loop just do this:

times++;

That's it. No more code needed. :)

And then you can print this value out once the loop is finished.

commented: Always trying to help +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.