Queue Simulation

My problem is I can't get it 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).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
case '5' :
      {
        int a[q.getCount()];
        int out[q.getCount()];
        cout<<"Enter simulator time: ";
        cin>>time;
        cout<<"Enter max minutes to enter queue: ";
        cin>>minute;
        cout<<"Enter max minutes to serve: ";
        cin>>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
         cout<<t+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
         t++;
         --out[j];
         cout<<t+1 <<setw(5)<<j+1 <<setw(5) <<a[j]+1 <<setw(5) <<out[j]<<endl;}}}
        cout<<endl;
}

      }
      break;
Topic archived. No new replies allowed.