May be a tough one

I have a code that acts as a login system. You can log into a computer, logout, search for users that are logged in, and then quit the program.

The computer lab looks like this:
Lab# Computers
1 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)
2 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)
3 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)
4 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)

The user selects the option to login to one of the computers with a five character username. The user logs into lab 2, computer 3, (lets say with username "abcde") After logging in the display SHOULD say this.

Lab# Computers
1 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)
2 1: empty 2: empty 3: abcde 4: empty 5: empty ...(Goes until 10)
3 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)
4 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)

Here's my problem: When logging in my display looks like
Lab# Computers
1 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)
2 1: empty 2: empty abcde 4: empty 5: empty ...(Goes until 10)
3 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)
4 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)

Where the 3 goes missing. I can't figure out how to keep the 3: so that the display reads:
Lab# Computers
1 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)
2 1: empty 2: empty 3: abcde 4: empty 5: empty ...(Goes until 10)
3 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)
4 1: empty 2: empty 3: empty 4: empty 5: empty ...(Goes until 10)

Here's two of the functions I used.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void showStatus()
{
     int i,j;
     cout<<"\nSTATUS\n";
     cout<<"Lab#    Computers\n";
     for(i=0;i<rows;i++)
     {
        cout<<(i+1)<<"\t";
        for(j=0;j<cols;j++)
        {
            if(labs[i][j]=="empty")
               cout<<(j+1)<<": empty  " ;
            else
               cout<<labs[i][j]<<"  ";
        }
        cout<<"\n";
     }
}



AND

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
void login()
{
     string id,tid;
     int i,j,labid,cid,flag=0;
     while(true)
     {
         cout << "Enter your 5-character ID to login: ";
         cin >> id;
         if (id == "empty")
             cout << "Invalid ID" << endl;
         else if(id.size() == 5)
         {
             cout << "Enter the lab # (1-4): ";
             cin >> labid;
             if(labid >= 1 && labid <= 4)
             {
                 cout << "Enter the Computer # (1-10): ";
                 cin >> cid;
                 if(cid >= 1 && cid <= 10)
                     break;
                 cout<<"\nInvalid computer id\n\n";
             }
             else
                cout<<"\nInvalid Input\n\n";
         }
         else
            cout<<"\nInvalid Input\n\n";
     }
     tid = labs[labid-1][cid-1];
     if(tid != "empty")
     {
         cout<<"ERROR, user "<<tid<<" is already logged into that station\n";
     }
     else
     {

         flag=0;
         for(i=0;i<rows;i++)
         {

            for(j=0;j<cols;j++)
            {
                if(labs[i][j]==id)
                {
                    flag=1;
                    labid=i;
                    cid=j;
                    break;
                }
            }
         }
         if(flag==1)
             cout<<"User "<<id<<" is in lab #"<<labid+1<<" at Computer #"<<cid+1<<"\n\n";
         else
              labs[labid-1][cid-1]=id;
     }
}

labs was defined under class and before public as string** labs;
Last edited on
1
2
3
               cout << (j+1) << ": empty  ";
            else
               cout          << labs[i][j]<<"  ";

You have that and you wonder why in
one case you print a number and a text
and in another case only text?
Welp that solves it.
Topic archived. No new replies allowed.