Problem with conditions in an ATM queue sim

I coded this ATM queue simulator for my ADS class's project.
What is needed is the following:

The program should ask the user to enter Opening t, Closing t, Customers Arrival t, customers arrival rate per sec and ATM serving rate per sec , then determine by simulating the situation using a queue:

Whether or not there will be a queue;
whether the size of the queue will grow, or remain constant. (I don't know what that suppose to mean?)
If the queue will grow, the program should determine the size of the queue at stopping time.

I completed the code in a simple way without the use of classes or functions.

The problem with my code:

-> When inputting an atm serving every T minutes < customers arrival time every Q minutes <-
the program doesn't work right!

I appreciate any suggestions, comments, problem fixing !
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
#include <queue>
#include <cmath>
#include <iostream>
using namespace std;

void main()
{
	queue <int> customers;
	int OPATMt, OPATMtm, CLATMt, CLATMtm, CusArrt, CusArrtm, CusArrEvtm;
	int AccOPtsec, CusArrtsec, CusArrEvtsecCLONE;
	int ATMserv , ATMservsec;
	cout << "Wlecome to the ATM simulator : \n ________________________________________________ " << endl;
	cout << " \n Please do as asked . \n Please input the follwing in 24 - hours format : " << endl;
	cout << "----- ----- ----- ----- ----- ----- ----- ----- ----- -----" << endl;
	cout << " Enter ATM openning time (hour 'space' minutes) : " << endl;
	cin >> OPATMt >> OPATMtm;
	cout << "Enter ATM closing time (hour 'space' minutes) :" << endl;
	cin >> CLATMt >> CLATMtm;
	cout << "Enter Customers arrival time (hour 'space' minutes) :" << endl;
	cin >> CusArrt >> CusArrtm;
	cout << "Customers arriving every (minutes) :" << endl;
	cin >> CusArrEvtm;
	cout << "ATM serving cusomers every (minutes) :" << endl;
	cin >> ATMserv;
	cout << "\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/"<<endl;
	//actual serving time
	int achoursdif = abs(CLATMt - OPATMt);
	int hourtomindiff = achoursdif * 60;
	int acmindif = abs(CLATMtm - OPATMtm);
	AccOPtsec = (hourtomindiff + acmindif) * 60;
	cout << "Acctual op time in secs " << AccOPtsec << endl;
	// Customers arrival rate per sec
	CusArrEvtsecCLONE = CusArrEvtm * 60;
	cout << "Customers arriving every  " << CusArrEvtsecCLONE <<" secs"<< endl;
	//Customers arrival time in sec
	int cusarrivh = abs(CusArrt - OPATMt);
	int cusarrivm = abs(CusArrtm - OPATMtm);
	CusArrtsec = (cusarrivh * 60 + cusarrivm )* 60;
	cout << "customers arriving after " << CusArrtsec <<" secs"<< endl;
	// ATM seving per sec
	ATMservsec = ATMserv * 60;
	cout << "ATM will serve every " << ATMservsec << " secs" <<endl;
	// ATM serving every sec counter
	static int ATMservCLONE = CusArrtsec;
	//customer arrival time counter
	static int CAC = CusArrtsec;
	// customer sample
	int customersample = 0;
	//served customers counter
	int customersserved = 0;
	//ATM started working
	cout << "ATM started working :" << endl;
	cout << "................................................." << endl;
	for (int sec = 0; sec < AccOPtsec; sec++)
	{
		//customers just arrived ( I'm inserting the same customer over and over because it's a sim, that isn't a problem right!)
		if (sec >= CusArrtsec)
		{
			//ATM is ready to serve
			if (sec == ATMservCLONE && sec != CAC || (sec == ATMservCLONE && sec == CAC))
			{
				//queue is empty
					if (sec == CAC && customers.empty())
					{
						//there is a customer who just arrived
						customersserved++;
						customersample++;
						cout << "customer in action" << endl;
						ATMservCLONE += ATMservsec;
						CAC = CAC + CusArrEvtsecCLONE;
					}
					else
					//ATM ready to serve and queue is >0
					//cutomer came but have to queue
					if (sec == CAC && !customers.empty())
					{
						customers.push(customersample);
						customersample++;
						customers.pop();
						customersserved++;
						cout << "customer in action" << endl;
						ATMservCLONE +=ATMservsec;
						cout << "please queue" << endl;
						CAC = CAC + CusArrEvtsecCLONE;
					}
					else
					if (!customers.empty() && sec != CAC)
					{
						customers.pop();
						customersserved++;
						cout << "customer in action" << endl;
						ATMservCLONE += ATMservsec;
					}
			} //2nd if
			else
			{
					//ATM not ready but customer arrived
					if (sec == CAC && sec != ATMservCLONE)
					{
						customers.push(customersample);
						customersample++;
						cout << "New customer, please queue" << endl;
						CAC = CAC + CusArrEvtsecCLONE;
					}
					//ATM not ready and no new customers
				//else
					//cout << "Please continue to queue until ATM is available." << endl;
			}

			//waiting for customers
		} // 1st if
	} // for

	cout << "------------------------------------------------------" << endl;
	cout << "It's closing time AT " << CLATMt << " : " << CLATMtm << endl;
	cout << "The ATM worked for " << AccOPtsec << " seconds." << endl;
	cout << "The total number of customers is : " << customersample <<" customer."<< endl;
	cout << "Customer served : " << customersserved << " customers." <<endl;
	// If there was a queue or not
	if (CusArrEvtm < ATMserv)
	{
		cout << "Customers had to queue." << endl;
	}
	else
	{
		cout << "There was no need for customers to queue." << endl;
	}

	cout << "Customers still queueing : " << customers.size() << endl;
	system("pause");
}
Last edited on
Topic archived. No new replies allowed.