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;
{
// 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;
}
#include <iostream>
#include <cstring>
usingnamespace 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;
}