C/C++ >> Can sombody help please stuck in it
Posted by speedy11 on 21:37:00 09-05-2001
I'm a complete first time starter,could someone help me out on this problem in C.
The rand() fuction is used to genetrate pseudo-random values.Can you write a program that uses the function to simulate people standing in a queue.The probability of someone arriving or departing the queue is 1 in 30 per second.The following function call can be usedto determin if an arrival has occurred.
rand() % 30 == 0
Another call function can be made to see if a departure has occured.
write a program to keep record of the number of people in the queue every second and printing the leghth of queue length each minute.Use loops to simulate the number of minutes and the number of seconds.The program should run for 20 mins.

I will learn from this its not a cheating thing i need help please.
Thanks
Posted by Peter on 12:21:00 09-09-2001
Hey! I am doing great with figuring out the timer functions! What I need is, how many people are standing in the queue initially?
Posted by Peter on 16:27:00 09-09-2001
Well I made that a variable and standard is 0.

Get http://www.ypr.34sp.com/Content/peter/queue.c

The program will run for 20 minutes as it is now. Actually, it is totally unnecessary to make the program run for 20 minutes as it could calculate the same thing instantly but this is also an example of timing.

Logically, the queue should stay around the same size all the time, but this progam usually makes it increase. I consider this a flaw in the statistics.

The prog is based upon what you said: it's 1/30 chance that an arrival or departure occurs. Well, people should more often leave than arrive, but in my prog it's only a 50% chance. I think that is where the flaw is, but it's not a big one and can easily be fixed, once you have some good statistical info.

[ This Message was edited by: Peter on 2001-09-09 16:32 ]