Movie Ticket Booking. Array,loop, string.

I am a trying to show the seating arrangement of a Cinema Hall consisting of 5 rows and 7 columns. Then, i have to ask the user to enter their seat choice and when they have typed in their choice, i have to reserved the seat with an asterisk'*' and i should ask the user again whether he wants to book another seat. So my problem here is how do i change the seat choice to an asterisk? Here is my code that i've done so far. If someone could help me to explain or do some examples that would be highly appreciated.
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
50
51
52
53
54
55
56
57
58
59
 #include<cstdlib>
#include<iostream>
#include<windows.h>
#include<iomanip>
#include<fstream>  
#include<string.h>

using namespace std;


int main() 

{
	int a;
	int b;
    char seats[5][40]=  {"A |_1_||_2_||_3_||_4_||_5_||_6_||_7_|",
                         "B |_1_||_2_||_3_||_4_||_5_||_6_||_7_|",
                         "C |_1_||_2_||_3_||_4_||_5_||_6_||_7_|",
                         "D |_1_||_2_||_3_||_4_||_5_||_6_||_7_|",
                         "E |_1_||_2_||_3_||_4_||_5_||_6_||_7_|"};
                      
    
    seats [a][b]='*';
    
	 for(a=0;a<5;a++)
             {
                     cout<<seats[a]<<endl<<endl;
             }
             
		cout<<endl;
		
	
	

	

                     
                   
	
{
    
	char choice;
	cout<<"Would like to choose another seat?(Please choose only 1 or 2)"<<endl;
	cout<<"(1) Yes"<<endl;
	cout<<"(2) No"<<endl;
	cin>>choice;
	if(choice=='1')
	{	
		main();
    }
	if(choice=='2')
	{
		exit(0);
	}
	 

}
	return 0;
}
hello,
I tried to follow as much as possible to your code.

in your code there are two problems:
1) the matrix that you wrote, it was just a drawing on the video, as it were giving to the positions indicated with a number, the corresponding element of the array.
2) in fact, lacked the ability to make a choice of the place on which to sit.

Hope that helps, even if late.

ciao

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
#include<iostream>
 using namespace std;

 char seats[5][8];

void roomMovie()
{
    int i,j;
    for ( i=0;i<5; i++)
        cout<<"|_ row n "<<i+1<<" _"<<seats[i][0]<<"_|"<<"_"<<seats[i][1]<<"_|"<<"_"<<seats[i][2]<<"_|"<<"_"<<seats[i][3]<<"_|"<<"_"<<seats[i][4]<<"_|"<<"_"<<seats[i][5]<<"_|"<<"_"<<seats[i][6]<<"_|"<<"_"<<seats[i][7]<<"_|"<<'\n';
        cout<<" input choice position ( row and column )"<<endl;
        cin>>i>>j;
        if (seats[i][j] != '1')
            seats[i][j] = '1';
        else
            {
                cout<<endl;
                cout<<" Warning : position not free. seek another."<<endl;
                cout<<endl;
            }
    for ( i=0;i<5; i++)
        cout<<"|_ row n "<<i+1<<" _"<<seats[i][0]<<"_|"<<"_"<<seats[i][1]<<"_|"<<"_"<<seats[i][2]<<"_|"<<"_"<<seats[i][3]<<"_|"<<"_"<<seats[i][4]<<"_|"<<"_"<<seats[i][5]<<"_|"<<"_"<<seats[i][6]<<"_|"<<"_"<<seats[i][7]<<"_|"<<'\n';
}

 int main()
 {
     for (int i=0; i<5; i++)
        for (int j=0; j<8; j++)
            seats[i][j] = 'O';
     bool choice = 1;
while (choice==true)
    {
     roomMovie();
     cout<< "Would like to choose another seat?(Please choose only 1 or 0)" <<endl;
     cout<< "(1) Yes" <<endl;
     cout<< "(0) No" <<endl;
     cin>>choice;
     if (choice==0)
        break;
    }
   return 0;
 }
Last edited on
Topic archived. No new replies allowed.