Help with program dealing with arrays! :)

Not as much of a question, more of a necessary peer review. I finished a program, but surprise! there's an error and my compiler cant catch it, please help me find it!

What the program does:
1. Assigns a user to a station in 1 of 4 labs
2.Lets admin check availability of lab stations
3.lets user log out

the problem is it isn't assingning or isn't finding if the stations are occupied after logging in... I tried to sign in and it says it did, but when I open admin view, all stations are still empty, also when i checked on debugger even though i initialize the array, strange values appear on them...

Please tell me what I did wrong if you can, got an exam tomorrow which is why i'm not setting myself to find it, cant waist that much time, thanks ahead! :)

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
  #include <iostream>

using namespace std;

void CheckAvail(int S[4][6]);//checks availability when prompt (where I think the problem is)
void UserSignIn(int Ser[4][6]);//main interface of the program (where the bug might be)
void AssignStat(int Sr[4][6],int Use,int Labs,int Stats);//assigns lab stations(highest % of being the bug)
void LogoutStat(int Sir[4][6],int Use,int Labs,int Stats);//logs users off not really related...

int main()
{
    int Server[4][6]={{0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0},{0,0,0}};

    UserSignIn(Server);




    return 0;
}

void CheckAvail(int S[4][6])
{int i,j,k,l,m;
for(i= 0; i < 4; i++)
{
    if(i == 0)
    {
        cout << endl << "Lab " << i+1<< "-->";
        for(j=0;j<5;j++)
    {

        if(S[i][j] == 0)
        {
            cout << j+1 <<": empty ";
        }
        else if(S[i][j] == 0 && j == 2)
        {
         cout << j+1 <<": empty " << endl;
        }
        else if(S[i][j] > 0 && j == 2)
        {
            cout << j+1<< ": " << S[i][j] << endl;
        }
        else if(S[i][j] > 0)
        {
            cout << j+1<<": " << S[i][j] <<" ";
        }

    }
    }

    else if(i == 1)
    {
        cout<< endl << "Lab " << i+1<< "-->";
        for(k=0;k<6;k++)
    {

        if(S[i][k] == 0)
        {
            cout << k+1 <<": empty ";
        }
        else if(S[i][k] == 0 && k == 2)
        {
         cout << k+1 <<": empty " << endl;
        }
        else if(S[i][k] > 0 && k == 2)
        {
            cout << k+1<< ": " << S[i][k] << endl;
        }
        else if(S[i][k] > 0)
        {
            cout << k+1<<": " << S[i][k] <<" ";
        }

    }
    }

    else if(i == 2)
    {
        cout << endl<< "Lab " << i+1<< "-->";
        for(l=0;l<4;l++)
    {

        if(S[i][l] == 0)
        {
            cout << l+1 <<": empty ";
        }
        else if(S[i][l] == 0 && l == 2)
        {
         cout << l+1 <<": empty " << endl;
        }
        else if(S[i][l] > 0 && l == 2)
        {
            cout << l+1<< ": " << S[i][l] << endl;
        }
        else if(S[i][l] > 0)
        {
            cout << l+1<<": " << S[i][l] <<" ";
        }

    }
    }

    else if(i == 3)
    {
        cout << endl<< "Lab " << i+1<< "-->";
        for(m=0;m<3;m++)
    {

        if(S[i][m] == 0)
        {
            cout << m+1 <<": empty ";
        }
        else if(S[i][m] == 0 && m == 2)
        {
         cout << m+1 <<": empty " << endl;
        }
        else if(S[i][m] > 0 && m == 2)
        {
            cout << m+1<< ": " << S[i][m] << endl;
        }
        else if(S[i][m] > 0)
        {
            cout << m+1<<": " << S[i][m] <<" ";
        }

    }
    }

}

}

void UserSignIn(int Ser[4][6])
{
    int choice,Lab,Station,UserId;
cout << "\nWelcome! Please input your choice as the number in front of your option\n";
cout << "1.Enter a lab and computer station.\n2.Admin view of lab assignment.\n3.LogOut of station.\n4.Exit Program.\n";
cin >> choice;

if(choice < 1 || choice > 4)
{
cout << "\nWow man, there is no choice on the menu with that number, nimrod...\nTry again!\n";
UserSignIn(Ser);
}

else{

switch(choice)
{
case 1:
    cout << "\nThese are the available labs and stations:\n";
    CheckAvail(Ser);
    cout << "\nEnter your UserId:";
    cin >> UserId;
    cout << "\nEnter the lab you will enter:";
    cin >> Lab;
    cout << "\nEnter station(warning!: Make sure station is vacant on table):";
    cin >> Station;
    cout << "\n";
    AssignStat(Ser,UserId,Lab,Station);
break;

case 2:
    cout << "\nThese are the lab stations:\n";
    CheckAvail(Ser);
    cout << "\nTo exit the program enter 0 or 1 to continue to main menu:\n";
    cin >> choice;
    if(choice == 0)
    {
        return;
    }
    else
    {
    main();
    }
    break;

case 3:
    cout << "\nTo log out enter the following:\nUserId:";
    cin >> UserId;
    cout << "\nLab:";
    cin >> Lab;
    cout << "\nStation:";
    cin >> Station;
    LogoutStat(Ser,UserId,Lab,Station);
    break;

case 4:
    cout << "\nGoodBye!\n";
    return;
    break;


}



}
}

void AssignStat(int Sr[4][6],int Use,int Labs,int Stats)
{

    if(Sr[Labs-1][Stats-1] != 0)
    {
        cout << "\nStation is taken, back to main menu with you.\nvery well Be gone now!\n";
        main();
    }
    else
    {   cout << "\nLogged in!\nLab: " << Labs << " Station: " << Stats<< " UserId: " << Use<< endl;
        Sr[Labs-1][Stats-1] = Use;
        main();
    }

}

void LogoutStat(int Sir[4][6],int Use,int Labs,int Stats)
{

    if(Use == Sir[Labs-1][Stats-1])
    {
    cout << "\nYou've been logged out.\nPress enter for program to exit!\n";
    Sir[Labs-1][Stats-1] = 0;
    CheckAvail(Sir);
    return;
    }

    else
    {
     cout << "\nSorry wrong id, can't log you out without proper Identification!\n";
     main();
    }
}

Topic archived. No new replies allowed.