program has stopped working

This program is to track user usage of computer for a few computer lab.
The problem is i always got that "program has stopped working" message in most of the program part.
The program is quite long to be seen through but i can wait.
Any modification or help is really appreciated.

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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#include <iostream>
#include <cstdlib>
#include <iomanip>

using namespace std;

void receiveInput ( int &USERID, int &MAKMAL, int &STESEN );
int menu ();
void search ( int USERID, int *LAB1[], int *LAB2[], int *LAB3[], int *LAB4[], int *LAB5[] );
void checkvacancy ( int USERID, int *LAB[], int STESEN );
void logoff ( int *LAB[], int STESEN );

int main()
{
	int loop=0, i, option1, option2, userID, makmal, stesen, *lab1, *lab2, *lab3, *lab4, *lab5;
	
	lab1 = new int [5];
	lab2 = new int [6];
	lab3 = new int [5];
	lab4 = new int [4];
	lab5 = new int [3];
	
	//initialize all labs station to empty
	for ( i = 0; i < 5; i++ )
		lab1[i] = 00000;
	for ( i = 0; i < 6; i++ )
		lab2[i] = 00000;
	for ( i = 0; i < 5; i++ )
		lab3[i] = 00000;
	for ( i = 0; i < 4; i++ )
		lab4[i] = 00000;
	for ( i = 0; i < 3; i++ )
		lab5[i] = 00000;
	
	//track which user is logged on to which station
	while ( loop == 0 )
	{
		cout << left << setw(15) << "KPU Number" << "Computer Station" << endl;
		
		cout << setw(15) << "1";
		for ( i = 0; i < 5; i++ )
		{
			if ( lab1[i] == 00000 )
				cout << setw(2) << i+1 << setw(8) << "Empty";
				
			else
				cout << lab1[i];
		}
		cout << endl;
		
		cout << setw(15) << "2";
		for ( i = 0; i < 6; i++ )
		{
			if ( lab2[i] == 00000 )
				cout << setw(2) << i+1 << setw(8) << "Empty";
				
			else
				cout << lab1[i];
		}
		cout << endl;
		
		cout << setw(15) << "3";
		for ( i = 0; i < 5; i++ )
		{
			if ( lab3[i] == 00000 )
				cout << setw(2) << i+1 << setw(8) << "Empty";
				
			else
				cout << lab1[i];
		}
		cout << endl;
		
		cout << setw(15) << "4";
		for ( i = 0; i < 4; i++ )
		{
			if ( lab4[i] == 00000 )
				cout << setw(2) << i+1 << setw(8) << "Empty";
				
			else
				cout << lab1[i];
		}
		cout << endl;
		
		cout << setw(15) << "5";
		for ( i = 0; i < 3; i++ )
		{
			if ( lab5[i] == 00000 )
				cout << setw(2) << i+1 << setw(8) << "Empty";
				
			else
				cout << lab1[i];
		}
		cout << endl;
		cout << endl;
		
		//main menu
		cout << "1. Administrator" << endl;
		cout << "2. Guest" << endl;
		cout << "3. Exit system" << endl << endl;
		cout << "Choose your option:";
		cin >> option1;
		
		switch (option1)
		{
			case 1:
				if ( menu () == 1 )
					{
						receiveInput(userID, makmal, stesen);
				
						if( makmal == 1 )
						checkvacancy (userID, &lab1, stesen);
						else if( makmal == 2 )
						checkvacancy (userID, &lab2, stesen);
						else if( makmal == 3 )
						checkvacancy (userID, &lab3, stesen);
						else if( makmal == 4 )
						checkvacancy (userID, &lab4, stesen);
						else if( makmal == 5 )
						checkvacancy (userID, &lab5, stesen);
					}
					
				else if ( menu () == 2 )
					search ( userID, &lab1, &lab2, &lab3, &lab4, &lab5 );
				break;
				
			case 2:
				cout << "1. Log in" << endl;
				cout << "2. Log off" << endl << endl;
				cout << "Choose your option:";
				cin >> option2;
				
				switch (option2)
				{
					case 1:
						receiveInput(userID, makmal, stesen);
				
						if( makmal == 1 )
						checkvacancy (userID, &lab1, stesen);
						else if( makmal == 2 )
						checkvacancy (userID, &lab2, stesen);
						else if( makmal == 3 )
						checkvacancy (userID, &lab3, stesen);
						else if( makmal == 4 )
						checkvacancy (userID, &lab4, stesen);
						else if( makmal == 5 )
						checkvacancy (userID, &lab5, stesen);
						break;
						
					case 2:
						cout << "Enter KPU number:";
						cin >> makmal;
						cout << endl;
						
						cout << "Enter computer station number:";
						cin >> stesen;
						cout << endl;
						
						if( makmal == 1 )
						logoff (&lab1, stesen);
						else if( makmal == 2 )
						logoff (&lab2, stesen);
						else if( makmal == 3 )
						logoff (&lab3, stesen);
						else if( makmal == 4 )
						logoff (&lab4, stesen);
						else if( makmal == 5 )
						logoff (&lab5, stesen);
						break;						
				}
				break;
				
			case 3:
				loop = 1;
				break;
		}
	}
	
	
	return 0;
}

void receiveInput ( int &USERID, int &MAKMAL, int &STESEN )
{
	int i, loop1=0, loop2=0;
	
	cout << "Enter user ID :";
	cin >> USERID;
	cout << endl;
	
	while ( loop1 == 0 )
	{
		cout << "Enter KPU number ( 1 to 5 ):";
		cin >> MAKMAL;
		cout << endl;
		
		if( MAKMAL < 1 || MAKMAL > 5 )
			cout << "Invalid input";	
		else
			loop1 = 1;
	}
	
	if ( MAKMAL == 1 )
		i = 5;
	else if ( MAKMAL == 2 )
		i = 6;
	else if ( MAKMAL == 3 )
		i = 5;
	else if ( MAKMAL == 4 )
		i = 4;
	else if ( MAKMAL == 5 )
		i = 3;
	
	while ( loop2 == 0 )
	{
		cout << "Enter computer station number ( 1 to " << i << " ):";
		cin >> STESEN;
		cout << endl;
		
		if( STESEN < 1 || STESEN > i )
			cout << "Invalid input";	
		else
			loop2 = 1;
	}
}

void checkvacancy ( int USERID, int *LAB[], int STESEN )
{
	if ( *LAB[STESEN] == 00000 )
	{
		cout << "Congratulation this station is available, enjoy your time :)" << endl;
		
		*LAB[STESEN] = USERID;
	}
	
	else
		cout << "Sorry this station is occupied, please choose another station" << endl;
}

void logoff ( int *LAB[], int STESEN )
{
	*LAB[STESEN] = 00000;
}

int menu ( )
{
	int option;
	
	cout << "1. Simulate user" << endl;
	cout << "2. Search user" << endl;
	cout << "Choose your option:";
	cin >> option;
	
	switch (option)
	{
		case 1:
			return 1;
			break;
			
		case 2:
			return 2;
			break;
	}
}

void search ( int USERID, int *LAB1[], int *LAB2[], int *LAB3[], int *LAB4[], int *LAB5[] )
{
	int i, search = 0;
	
	for ( i = 0; i < 5; i++ )
	{
		if ( USERID == *LAB1[i] )
		{
			cout << "User ID " << USERID << " is in KPU 1 station number " << i << "." << endl;
			search = 1;
		}
	}
	
	for ( i = 0; i < 6; i++ )
	{
		if ( USERID == *LAB1[i] )
		{
			cout << "User ID " << USERID << " is in KPU 2 station number " << i << "." << endl;
			search = 1;
		}
	}
	
	for ( i = 0; i < 5; i++ )
	{
		if ( USERID == *LAB1[i] )
		{
			cout << "User ID " << USERID << " is in KPU 3 station number " << i << "." << endl;
			search = 1;
		}
	}
	
	for ( i = 0; i < 4; i++ )
	{
		if ( USERID == *LAB1[i] )
		{
			cout << "User ID " << USERID << " is in KPU 4 station number " << i << "." << endl;
			search = 1;
		}
	}
	
	for ( i = 0; i < 3; i++ )
	{
		if ( USERID == *LAB1[i] )
		{
			cout << "User ID " << USERID << " is in KPU 5 station number " << i << "." << endl;
			search = 1;
		}
	}
	
	if ( search == 0 )
		cout << "None" << endl;
}
fast fix:
Lines 226-242:
1
2
3
4
5
6
7
8
9
10
11
12
void checkvacancy ( int USERID, int *LAB[], int STESEN )
{
	if ( (*LAB)[STESEN] == 00000 )
	{
		cout << "Congratulation this station is available, enjoy your time :)" << endl;
		
		(*LAB)[STESEN] = USERID;
	}
	
	else
		cout << "Sorry this station is occupied, please choose another station" << endl;
}

Change other places accordingly.
good fix:
Line 226:
1
2
void checkvacancy ( int USERID, int LAB[], int STESEN )
                                    ↑

Modify your calls to that function, array operations inside it (delete dereference operator) and modify other functions accordingly. Note that arrays in C++ does not passed by value. Arrays very sililar to pointers actually, youcan do stuff like:
1
2
3
4
5
6
7
int array[5] = {0, 1, 2, 3, 4};
array[3];//3
*array;//0
*(array + 1);//1
(array + 2)[0];//2
(array + 1000)[-999];//1
2[array];//2 - really blows your mind does it? 
and also following function declaration are eqyivalent:
1
2
void foo(int* array);
void foo(int array[]);
Topic archived. No new replies allowed.