Code:
// Symbolic Constants
#define ROWS 7
#define COLS 4
//---------------------------------------------------------------------------
char seat[7][COLS]; //COLS+1 for terminating character.
int main()
{
for(int i = 0; i < ROWS; ++i)
{
for(int j = 0; j < COLS; ++j)
{
seat[i][j]= j+'A';
}
}
for(int i = 0; i < ROWS; ++i)
{
cout<< (i+1);
for(int j = 0; j < COLS; ++j)
{
cout<< " " << seat[i][j];
}
cout<< endl;
}
//Let's take seat at position [3,2]. Since indexes start at 0 we need to
//substract 1: position = [3-1][2-1].
//Asking for user input
char aisle; //for rows
char seat; //for coulumns
cout<< "Please enter your desired seat no. (eg, 3A): ";
cin >> aisle >> seat;
int row = aisle -'0' - 1; //to calculate the row
int col = seat - 'A'; //to calculate the column
seat[3][2] = 'X';
cout<<endl<<"After taking a seat:"<<endl<<endl;
for(int i = 0; i < ROWS; ++i)
{
for(int j = 0; j < COLS; ++j)
{
cout<<seat[i][j];
}
cout<<endl;
}
cout << endl << endl << endl << "Press Any Key to Continue...";
getch ();
return 0;
}
But I get a error "Invalid Indirection" at seat[3][2] = 'X';
and another one is same "Invalid Indirection" at cout<<seat[i][j];
So please let me know what I'm doing wrong.
Thanks