first time working in arrays

Hi I am working on an assignment where I am supposed to create an array to store a parking lot of 10 slots. I am setting up a switch to read whether the slot is open closed or in use. currently my switch is not reading something as it always returns the default value. can anyone explain what I am doing wrong and help me with a fix?

Here is the code:

#include <iostream>

#include <cstring>

using namespace std;

char wait;

int main()

{
// this variable is for later code please ignore.
int lotChoice;
int lotNum = 1;

int lotStatus = 1;

// print the array values

int parkingLot[10] = {0};

char readPLot [3][10] = {"Open" , "InUse", "Closed"} ;

int count = 0;


while (count < 10)

{
// this is where I am having trouble I want the array parkinglot to compare its // value at arraynumber whatever count is to 0, 1, 2 and put the following
// text to it thanks !!!
switch (parkingLot [count])
{
// Open slot
case '0':
cout <<"lot number " << parkingLot [lotNum] <<"is " << readPLot [0] << endl;
break;
// inuse slot
case '1':
cout <<"lot number " << parkingLot [lotNum] <<"is " << readPLot [1] << endl;
break;
// closed slot
case '2':
cout <<"lot number " <<parkingLot [lotNum] <<"is " << readPLot [2] << endl;
break;
default :
cout <<"lot number " <<parkingLot [lotNum] << "error" << endl;
break;
}

count++;
lotNum ++;
}
cin >> wait;
}
your here
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
#include <iostream>
#include <cstring>

using namespace std;

int main()

{
// this variable is for later code please ignore.
    int lotChoice;
    int lotNum = 0;

    int lotStatus = 1;

// print the array values

    int parkingLot[10] = {0,1,2,3,4,5,6,7,8,9};

    char readPLot [3][10] = {"Open" , "InUse", "Closed"} ;

    int count = 0;


    while (count < 10)

        {
        // this is where I am having trouble I want the array parkinglot to compare its // value at arraynumber whatever count is to 0, 1, 2 and put the following
        // text to it thanks !!!
            switch (parkingLot[count++])
                {
                    // Open slot
                    case 0:
                        cout <<"lot number " << parkingLot [lotNum++] <<" is " << readPLot [0] << endl;
                                break;
                    // inuse slot
                    case 1:
                        cout <<"lot number " << parkingLot [lotNum++] <<" is " << readPLot [1] << endl;
                                break;
                    // closed slot
                    case 2:
                        cout <<"lot number " <<parkingLot [lotNum++] <<" is " << readPLot [2] << endl;
                                break;
                    default :
                        cout <<"lot number " <<parkingLot [lotNum++] << " error " << endl;
                }

        };
    return 0;
}

have a nice day
Topic archived. No new replies allowed.