Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   c++ Queue Simulation (http://www.go4expert.com/forums/cpp-queue-simulation-t24017/)

pkjm17 28Nov2010 08:42

c++ Queue Simulation
1 Attachment(s)
Hi, my problem here is I can't get my program to output if another person enters the queue at a minute which the person before them is still being served. I think I need to put something after my while statement? Here's an example of what I'm talking about. On one of my runs, it skipped person #4, because they must have entered somewhere at a minute when person #3 was still being served (counting down to zero). Please see attached screen shot image of what I mean.


case '5' :
        int a[q.getCount()];
        int out[q.getCount()];
        cout<<"Enter simulator time: ";
        cout<<"Enter max minutes to enter queue: ";
        cout<<"Enter max minutes to serve: ";
        cout<<"Queue Size: " <<q.getCount() <<endl <<endl;
        cout<<"MINUTE"<<setw(10)<<"PERSON #"<<setw(3)<<"IN"<<setw(10)<<"SERVE" <<endl;
        a[0] = rand() % (minute - 1) + 1 + 1;
        for(int i=1; i<q.getCount(); i++) //get arrival time
            a[i] = a[i - 1] + rand() % (minute - 1) + 1 +1;

        for(int s=0; s<q.getCount(); s++)//get serve minutes
          out[s] = rand()%(serve-1)+1+1;

        for(int t=0; t<time; t++){//begin loop start with minute 1

        for(int j=0; j<q.getCount(); j++){
            if(a[j] == t){ //minute equals minute entering queue
            cout<<setw(5)<<j+1 <<setw(5) <<a[j]+1 <<setw(5) <<out[j]<<endl; //<<rand()%(serve-1)+1+1;//print current person
        while(out[j] != 0){//print until serve minute is at zero
        cout<<t+1 <<setw(5)<<j+1 <<setw(5) <<a[j]+1 <<setw(5) <<out[j]<<endl;}}}


All times are GMT +5.5. The time now is 08:03.