PDA

Click to See Complete Forum and Search --> : c question


Robert Briggs
Nov 8th, 2000, 05:02 AM
To all you intelligent people out there
Can someonehelp ? the question is I need to write a pgm that simulates people standing in queue the probability of someone arriving or departing the queue is 1 in 30 per second using the rand function rand() %30 ==0
I then need to call to the function to see if a departure has occured.

I need to write a pgm that will keep a record of the no of people in the queue every second and printing the queue length each minute. using loops to simulate the no of minutes and no of seconds The pgm should run for 20 minutes.

Many thanks


I have another e-mail address( home) robert.briggs1@ntlworld.com if this site is difficult to e-mail.
Bob Briggs

HarryW
Nov 8th, 2000, 08:53 AM
int peepsInQ = INITIAL_Q_LEN;

for (int mins=0; mins<20; mins++)
{ for (int secs=0; secs<60; secs++)
{ if (rand()%30==0)
peepsInQ++; //someone joins the Q

if (rand()%30==0)
peepsInQ--; //someone leaves the Q
}
printf("Minute %i, people in the Q = %i.\n", min, peepsInQ);
}


Think that should do what you want. Probably a few semicolons missing here and there ;)