How will i do this? (A hint would be nice)

Hey guys im working on a assignment and im stuck at the last part now im not asking you to do it for me im just asking for at least a hint.

now what the assignment says is i should create 2 data members and assignment them the departure time and arrival time now i can do that i just cant seem to figure out how to keep a 2 hour difference between them. here is what they say i need to do.

Departure Time and Arrival Time
Both these will be generated randomly and must have at least difference of two hours in-between departure time and arrival time.

Last edited on
You could do something like:

1
2
3
4
5
6
7
8
float DepartureTime, ArrivalTime;

DepartureTime = //Your code here for finding a random time;

do
{
    ArrivalTime = //Your code here for finding a random time;
} while (ArrivalTime - DepartureTime < 2 hours);
hmm im having a little trouble understanding the while part?... it will assign a random time to arrival time until the difference of arrival time and departure time is less than 2 hours? that doesn't seem right.

please correct me if im wrong.

what i need to do is that i need to keep a 2 hour difference between arrival time and departure time not the diffrence of arrival time and departure time less than 2 hours.
Last edited on
What the do while loop above does is:

1. Assigns ArrivaleTime a random time.
2. If the difference is less than two hours try assigning a new value..
3. Repeat until the difference is above 2 hours.

If you know that arrival and departure have EXACTLY 2 ours difference then all you need is ONE random number. The other comes out as difference.

Is this what you want?
Topic archived. No new replies allowed.