Simulation program queuesystem

Hi! Im having problem with My code where i can't enter the last if.
This simulates a queuesystem.
Are My calculations right?

Seems like everything becomes 0 in size and servicetime...
Help!


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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <iostream>
#include <cstdlib>
#include <list>
#include <ctime>
#include <time.h>
#include <stdlib.h>
#include<windows.h>


using namespace std;

class Customer
{
public:

    int servicet;
    int served;

    Customer()
    {
        servicet= rand()%150+30;
    }

    int getServicetime()
    {
        return servicet;
    }

    int getServed()
    {
        return served;
    }


    int decreaseServeTime()
    {
        servicet --;
    }

};


int totServed=0;
int queues=0;
int inLine=0;
int totTime=0;
int smallestQueue=0;
int temp=0;
int ran=0;
double mean=0;
int served=0;
int serviceTime=0;
int help=0;
int sim=0;
int n=0;
using namespace std;
int main()
{
    cout<<"Number of Cashiers?: "<<endl;
    cin >> queues;
    cout <<"How long simulation?: "<<endl;
    cin >> sim;
    cout <<endl;

    list<Customer> *cashiers[queues];
    list<Customer> *cust;


    for(int i=0; i<=queues; i++)
    {
        cust = new list<Customer>;
        cashiers[i] = cust;


    }

    srand(time(0));
    while(n<sim)
    {
        Sleep(2000);


        ran= rand()%4;
        smallestQueue = cashiers[0] ->size();

        for(int j=0; j<ran; j++)
        {
            for(int k=0; k<queues; k++)
            {
                temp = cashiers[k]->size();

                if(temp<=smallestQueue)
                {
                    smallestQueue = temp;

                    help=k;
                }
            }

            Customer C;

            cashiers[help]->push_back(C);
            inLine++;

        }

        for(int i=0; i<queues; i++)
        {
            if(serviceTime>0)
            {

                serviceTime = cashiers[i]->front().getServicetime();
                cashiers[i]->front().decreaseServeTime();

            }
            else if(serviceTime==0)
            {
                if(cashiers[i]->size()!=0){
                cashiers[i]->pop_front();
                served++;
                }
            }
        }

        totTime++;
        int cash=1;
        for(int i=0; i<queues; i++)
        {
            inLine = cashiers[i]->size();
            if(inLine!=0)
            {
                cout <<"Kassa: "<<cash<<endl;
                mean = (totTime/inLine);
                totServed +=served;
                cash++;


            }
            cout <<"In this line: "<<inLine<<" \nMean time this line: "<<mean<<" \nAll served: "<<totServed;

        }
        cout <<endl;
        cout <<endl;
        cout <<"Total time: "<<totTime;
        cout <<endl;
        cout <<endl;


    n++;
    }

    system("pause");




}
Topic archived. No new replies allowed.