Problem with my loop

My problem here is for my simulation the minutes are off. For example, on one of my runs, Person #1 arrives at minute 6, but why does it show them arriving at minute 1 when the loop just begins? It should start them at minute 6. This is the output I'm getting.

MINUTE PERSON IN(arriving minutes) OUT(serving minutes)
1 1 6 3
2 1 6 2
3 1 6 1
4 1 6 0

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
35
36
37
38
39
case '2' : //Run simulation
        {
            int t = 0;
            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(5)<<"IN"<<setw(10)<<"SERVE" <<endl;
            a[0] = rand() % (minute - 1) + 1 + 1;
            for(int i=1; i<q.getCount(); i++) //get arrival minute
                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;

            while(t < time){//begin loop start with minute 1
                t++;
                cout<<t;

            for(int j=0; j<q.getCount(); j++){
                if(a[j] && t<= a[j])// if( not processed && some one still needs processing
                    cout<<setw(width) <<j+1 <<setw(width) <<a[j]+1 <<setw(width) <<out[j] <<endl;

            for(int c=out[j];c>0;c--){//print out serve minutes until zero
              t++;
              --out[j];
              cout<<t<<setw(width) <<j+1 <<setw(width) <<a[j]+1 <<setw(width) <<out[j] <<endl;}//end of for loop
              a[j]=NULL;
            }//end of for loop
            cout<<endl;
            }//end of while loop
            cout<<endl;
            break;
        }
I would need a better explanation of the problem in order to help you.

"//begin loop start with minute 1" that's the only thing that stands out to me.
Topic archived. No new replies allowed.