Results 1 to 2 of 2

Thread: c question

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Mirfield,West Yorkshire,Englan
    Posts
    11

    Stop looking and help muggles

    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) [email protected] if this site is difficult to e-mail.
    Bob Briggs

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Code:
    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
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width