1  2  3  4    5  6  7  8 9 10 11 12 13 14 15 16    17  18  19 20
A  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
B  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
C  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
D  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
E  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
F  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
                                             
G  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
H  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
I  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
J  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
K  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
L  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
                                             
M  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
N  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
O  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
P  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
                    S C  R  E  E  N
1  2  3  4    5  6  7  8 9 10 11 12 13 14 15 16    17  18  19 20
A  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
B  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
C  *  *  *  *    *  *  x  x x x  x  x  x  x  *  *    *  *  *  * 
D  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
E  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
F  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
                                             
G  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
H  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
I  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
J  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
K  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
L  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
                                             
M  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
N  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
O  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
P  *  *  *  *    *  *  *  * * *  *  *  *  *  *  *    *  *  *  * 
                    S C  R  E  E  N

i have to change the "*" to "x" like the above display example.
but its seems like i cant display the x..any body can help me?please..

#include <iostream>
 #include <cstdlib>
 #include <string>
 
 using namespace std; //used for cout and endl
 
 void displayMenu()
 {

	 system ("cls");
	 cout << " +-------------------------------------------+" << endl;
	 cout << " |         cinema seating project            |" << endl;
	 cout << " |===========================================|" << endl;
	 cout << " | Select :                                  |" << endl;
	 cout << " | 1 => Seat assignment                      |" << endl;
	 cout << " | 2 => Payments (for reserved seats)        |" << endl;
	 cout << " | 3 => Reset Seating Plan                   |" << endl;
	 cout << " |===========================================|" << endl;
	 cout << " | Q => Quit                                 |" << endl;
	 cout << " +-------------------------------------------+" << endl;
	 cout << endl;
	 cout << " Choice : " ;

 }

 void displaySeat(  char cinema[][20] ) //display seat 
 {

	 cout << endl;
	 cout << "             door                                  door          "<< endl;
	 cout << "_____________|  |__________________________________|  |___________"<< endl;
	 cout << endl;

	 cout << endl;
	 cout <<"-------------------------------------------------------------------"<<endl;
	 cout << endl;

	 int row ;
	 int column;
	
	 for( int row = 0; row < 17; ++row )
	 for( int column = 0; column < 20; ++column )
	 {
		 cinema[row][column] = '*';
	 }
 
	 for(row = 0; row < 17 ; row++)
	 {
		if( row == 7 || row == 13 ) //adds row spacers
			 
			 cout << endl;
			 
		cout << char(bool(row)*32+' '+row) << " "; //gets rid of the char array of A B C...
		for( column = 0; column < 20; column++ )
		{
			if(column == 0 || column == 4 || column == 16)
			{
				cout << " "; //adds column spacers
			}
			if( row == 0 ) //prints numbers along the topc
				{
				cout.width(2);
				
				cout << column+1 << " ";
				}
			else
				cout << " " << cinema[row][column] << " "; //prints each seat
		}
		cout << endl;
 	 }
	 

	 cout << endl;
	 cout << "       |D|------------------------------------------------|D|     "<<endl;
	 cout << " ______|O                 CINEMA SCREEN                    O|_____"<<endl;
	 cout << "        O                                                  O      "<<endl;
	 cout << "        R                                                  R      "<<endl;

	 cout << endl;
	 
	 return;

}


  void assignSeat(char cinema[][20]) // seat choose function
{
     int i ; // row
	 int j; // column

     char seatcol;
	 char more='Y';
	 
     do
     {
         cout<<"  Please enter seat desired A-P :";
		 cin>>seatcol;
		 cout<<endl;
	
		 seatcol=toupper(seatcol);//change to upper case so that can always subtract 'A'
		 i=( seatcol-'A' ) + 2; //by subtracting A, it changes A to 0, B to 1, C to 2, D to 3

        while(i>17||i<1)
        {
            cout << i << endl;
            cout <<" invalid seat" << endl;
            cout << " Enter Seat desired A-"<<(char)('A'-17)<<" : ";
            cin >> seatcol;
            seatcol=toupper(seatcol);
            i = (seatcol-'A') + 2;
        }

 

        cout<<"  Please enter the row number 1-20 :";
        cin>>j;
        cout<<endl;

        while(j>=21||j<=0)
        {
            cout<<"  invalid input of row,please enter again"<<endl;
            cout<<"  the row number 1-20 :";
            cin>>j;
            cout<<endl;
        }

         if( cinema[i][j]=='X')
         cout<<" Seat already chosen-rechoose"<<endl;
		 }while (cinema[i][j]=='X');
		  cinema[i][j]='X';
		 
	 return ;


	 }

 int main ()
 {

	 char choice;
	 bool done = false;
	  char cinemas[17][20];


	 do
	 {
         
   
		 displayMenu ();
		 cin >> choice;
		 choice = toupper (choice);
		 char more='Y';
		 
		 switch (choice)
		 {

            case '1' :  displaySeat(cinemas);
						while(left>0&&toupper(more)=='Y') // repeat function seating for next seat book
						 {
							 assignSeat(cinemas);
							 displaySeat(cinemas);
							 cout<<"choose another seat(Y/N)? ";
							 cin>>more;
						 }
						 system("pause");
                        break;
            case '2' : cout << "Not yet implement" << endl;
                        system("pause");
                        break;
            case '3' : cout << "Not yet implement" << endl;
                        system("pause");
                        break;
            case 'Q' : done = true;
                        break;
            default : cout << " Invalid selection, try again " << endl;
                        system ("pause");
                        break;
		 }

	 } while (!done) ;

	 cout << " thanks for using this program ! " << endl;
	 cout << endl;

	 return 0;

 }

Edited 5 Years Ago by Nick Evan: Added code-tags to preserve formatting

All you need to do is actually set the position in "char cinemas[17][20];" to 'X' when a seat is occupied. The displaySeat() function will take care of whatever is in the 2-dimensional array.

But it looks like you're doing too many things at once.
You should break this into smaller functions to reduce confusion on just setting the value so you can see WHEN the value is to actually be set.

Comments
good suggestions

i`m sorry..i still cant get it..could u explain more bout set the position char cinemas[17][20] to x..thats the only part that i still cant get it..

Hi,

Your entire program is almost correct.

Only problem is you are resetting your cinemas in display function:

// This is in your display function. so just before display its resetting your entire array.
	 for( int row = 0; row < 17; ++row )
	 for( int column = 0; column < 20; ++column )
	 {
		 cinema[row][column] = '*';
	 }

Remove that code and take it to the main, you need to set cinemas to "*" only once.

so your main should look like this:

int main ()
{

	char choice;
	bool done = false;
	char cinemas[17][20];

	for( int row = 0; row < 17; ++row )
		for( int column = 0; column < 20; ++column )
		{
			cinemas[row][column] = '*'; //NOTICE spelling of cinemas, in your display its cinema, as that is the name of your parameter, but in main its cinemas.
		}
      
        //Rest of the code.
         
}

Edited 5 Years Ago by alwaysLearning0: n/a

#include <iostream>
 #include <cstdlib>
 #include <string>
 
 using namespace std; //used for cout and endl
 
 void displayMenu()
 {

	 system ("cls");
	 cout << " +-------------------------------------------+" << endl;
	 cout << " |         cinema seating project            |" << endl;
	 cout << " |===========================================|" << endl;
	 cout << " | Select :                                  |" << endl;
	 cout << " | 1 => Seat assignment                      |" << endl;
	 cout << " | 2 => Payments (for reserved seats)        |" << endl;
	 cout << " | 3 => Reset Seating Plan                   |" << endl;
	 cout << " |===========================================|" << endl;
	 cout << " | Q => Quit                                 |" << endl;
	 cout << " +-------------------------------------------+" << endl;
	 cout << endl;
	 cout << " Choice : " ;

 }

 void displaySeat(  char cinema[][20] ) //display seat 
 {

	 cout << endl;
	 cout << "             door                                  door          "<< endl;
	 cout << "_____________|  |__________________________________|  |___________"<< endl;
	 cout << endl;

	 cout << endl;
	 cout <<"-------------------------------------------------------------------"<<endl;
	 cout << endl;

	 int row ;
	 int column;
	
	
 
	 for(row = 0; row < 17 ; row++)
	 {
		if( row == 7 || row == 13 ) //adds row spacers
			 
			 cout << endl;
			 
		cout << char(bool(row)*32+' '+row) << " "; //gets rid of the char array of A B C...
		for( column = 0; column < 20; column++ )
		{
			if(column == 0 || column == 4 || column == 16)
			{
				cout << " "; //adds column spacers
			}
			if( row == 0 ) //prints numbers along the topc
				{
				cout.width(2);
				
				cout << column+1 << " ";
				}
			else
				cout << " " << cinema[row][column] << " "; //prints each seat
		}
		cout << endl;
 	 }
	 

	 cout << endl;
	 cout << "       |D|------------------------------------------------|D|     "<<endl;
	 cout << " ______|O                 CINEMA SCREEN                    O|_____"<<endl;
	 cout << "        O                                                  O      "<<endl;
	 cout << "        R                                                  R      "<<endl;

	 cout << endl;
	 
	 return;

}


  void assignSeat(char cinema[][20]) // seat choose function
{
     int i ; // row
	 int j; // column

     char seatcol;
	 char more='Y';
	 
     do
     {
         cout<<"  Please enter seat desired A-P :";
		 cin>>seatcol;
		 cout<<endl;
	
		 seatcol=toupper(seatcol);//change to upper case so that can always subtract 'A'
		 i=( seatcol-'A' ) + 2; //by subtracting A, it changes A to 0, B to 1, C to 2, D to 3

        while(i>17||i<1)
        {
            cout << i << endl;
            cout <<" invalid seat" << endl;
            cout << " Enter Seat desired A-"<<(char)('A'-17)<<" : ";
            cin >> seatcol;
            seatcol=toupper(seatcol);
            i = (seatcol-'A') + 2;
        }

 

        cout<<"  Please enter the row number 1-20 :";
        cin>>j;
        cout<<endl;

        while(j>=21||j<=0)
        {
            cout<<"  invalid input of row,please enter again"<<endl;
            cout<<"  the row number 1-20 :";
            cin>>j;
            cout<<endl;
        }

         if( cinema[i][j]=='X')
         cout<<" Seat already chosen-rechoose"<<endl;
		 }while (cinema[i][j]=='X');
		  cinema[i][j]='X';
		 
	 return ;


	 }

 int main ()
 {

	 char choice;
	 bool done = false;
	  char cinemas[17][20];
	   for( int row = 0; row < 17; ++row )
	 for( int column = 0; column < 20; ++column )
	 {
		 cinemas[row][column] = '*';
	 }

	 do
	 {
         
   
		 displayMenu ();
		 cin >> choice;
		 choice = toupper (choice);
		 char more='Y';
		 
		 switch (choice)
		 {

            case '1' :  displaySeat(cinemas);
						while(left>0&&toupper(more)=='Y') // repeat function seating for next seat book
						 {
							 assignSeat(cinemas);
							 system ( "cls" );
							 displaySeat(cinemas);
							 cout<<"choose another seat(Y/N)? ";
							 cin>>more;
							 
							 
						 }
						 system("pause");
                        break;
            case '2' : cout << "Not yet implement" << endl;
                        system("pause");
                        break;
            case '3' : cout << "Not yet implement" << endl;
                        system("pause");
                        break;
            case 'Q' : done = true;
                        break;
            default : cout << " Invalid selection, try again " << endl;
                        system ("pause");
                        break;
		 }

	 } while (!done) ;

	 cout << " thanks for using this program ! " << endl;
	 cout << endl;

	 return 0;

 }

ok..ive done what u did..but still the seats didnt change to "x"

for

f

or( int row = 0; row < 17; ++row )
	 for( int column = 0; column < 20; ++column )
	 {
		 cinema[row][column] = '*';
	 }

u said it was resetting my display?i guess i can put it in void reset then.. :)

Edited 5 Years Ago by teha_toshio: n/a

whats is still wrong with my coding?i`ve tried for hours but still nothing good comes out from it.. =.=

Barring an off-by-one error in your array indexing, it works fine on my end.

Narue is correct. It works fine at my side as well.

Try for sit D and row 8, it is somewhere in the middle. at least you should see X
Then fix your array indexing.

Edited 5 Years Ago by alwaysLearning0: n/a

This question has already been answered. Start a new discussion instead.