Thread: For Stoned Coder

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    13

    For Stoned Coder

    This Is What I Have Come Up With.I think it is good enough what do you think??
    (NOTE!!! This Will Run For 20 MINS)
    #include <stdio.h>
    #include <time.h>

    /*** Function declaration ***/
    void anotherMinute(void);
    /**/

    /*** Global variable ***/
    int peopleInQueue;
    /**/

    /*** Arrivals and departures within a minute ***/
    void anotherMinute(void) {
    time_t t1,t2;
    char thisrand;

    t1 = time(NULL);
    t2 = time(NULL);

    while(t1) {
    if(difftime(t2,t1)==1) {

    if((rand() % 30)==0) {
    thisrand = rand()%2;
    if(thisrand)
    peopleInQueue++;
    else if (!thisrand && peopleInQueue)
    peopleInQueue--;
    }

    }
    if(difftime(t2,t1)==60) break;
    t2 = time(NULL);
    }

    }
    /**/

    int main(void) {
    int i;
    int totalTime; /* Desired time in minutes */

    peopleInQueue = 0; /* Define number of people initially in queue */
    totalTime = 20;

    for(i=0; i < totalTime; i++) {
    anotherMinute();
    printf("After %d minutes: %d people standing in queue\n", i+1, peopleInQueue);
    }

    return 0;
    }

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    well when i gave you the answer to your question yesterday i didn't realise you actually had to run the program for 20 mins.... I just thought you wanted to simulate a queue for 20 minutes.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ coder needer for a HL2 Mod
    By Cyph3rs in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 07-31-2005, 06:06 PM
  2. Programmer (vs) Coder
    By Brain Cell in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 03-24-2005, 01:59 PM
  3. Half Life 2 mod coder needed
    By pantsOFFinPUBLI in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 03-22-2005, 08:02 PM