need help!!

hello everybody ...
i am trying to do a cinema reservation .. but i have problem with the seats ...
this is my code for now
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
    #include <iostream>
    #include <string>
    using namespace std;
int main()
{
    string seatPlan [5][5];

    string cols ;
    string rows;
       cout<<"A "<<"B "<<"C "<<"D "<<"E "<<endl;
    for (int i=0;i<5;i++){

    for (int j=0;j<5;j++){
    cout<<seatPlan[i][j];
    cout<<' * ';
    }
    cout<<endl;
    }
    cout<<"Please enter seat row and column you wish to reserve: \n";
    cout<<endl;
    for (int i=0;i<5;i++){

    cin>>rows;
    cin>>cols;
    seatPlan[rows][cols];//--- there is problem here ??!!
    }
    }


here i want to make the user chose the seat as A5 or A6
but i dont know how to do it?? what datatype i should use ??!!
and how i make the seat like this ((THE NUMBER OF ROWS))
- A B C D E
1 * * * * *
2 * * * * *
3 * * * * *
4 * * * * *
5 * * * * *
Your problem is in line 25. You are trying to call an array while using strings as the indicies. This won't work. To call an array element you need to put integers (or ints) in the square brackets.

try:
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
char cRows;
int iRows, iCols;

cin >> cRows;
cin >> iCols;

switch(cRows)
{
case 'A':
case 'a':
    iRows=0; break;
case 'B':
case 'b':
    iRows=1; break;
case 'C':
case 'c':
    iRows=2; break;
case 'D':
case 'd':
    iRows=3; break;
case 'E':
case 'e':
    iRows=4; break;
}
seatPlan[iRows][iCols];



Last edited on
Another option which will take fewer lines of code:

1
2
3
4
5
6
7
8
9
10
char cRows;
int iRows, iCols;

cin >> cRows;
cin >> iCols;

while (cRows > 0xf) cRows -= 0x10;
iRows = cRows-1;

seatPlan[iRows][iCols];


This will map the ASCII characters to their respective numbers (A=1, b=2, etc.) as per:
http://www.cplusplus.com/doc/ascii/

Note it will not map anything larger than 'O' correctly.
OKAY I CHOOSE THE FIRST ONE ...
BUT how can i put (*) instead of 0 in seat plan AND WHEN I CHOOSE A SEAT IT CHANGED TO "R".
- A B C D E
10 0 0 0 0
20 0 0 0 0
3 0 0 0 0 0
4 0 0 0 0 0
5 0 0 0 0 0
THIS IS THE CODE
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
int seatPlan [5][5]= {0};

   char cRows;
int iRows, iCols;

cin >> cRows;
cin >> iCols;
for(int i =0;i<5;i++){
    for (int j=0;j<5;j++)



switch(cRows)
{
case 'A':
case 'a':
    iRows=0; break;
case 'B':
case 'b':
    iRows=1; break;
case 'C':
case 'c':
    iRows=2; break;
case 'D':
case 'd':
    iRows=3; break;
case 'E':
case 'e':
    iRows=4; break;
}
seatPlan[iRows][iCols-1]= 1 ;
    }


       for (int i=0;i<5;i++){
    for (int j=0;j<5;j++){
    cout<<seatPlan[i][j];
    cout<<" ";
    }
    cout<<endl;
    }
    }
Thanks Stewbond this while is great .
while( cRows > 0xf ) cRows -= 0x10;
Last edited on
cRows - 'A'
Topic archived. No new replies allowed.