Making a Theater Program

closed account (Eb09LyTq)
Hello, I'm looking for help with creating a program that makes a multidimensional array and the user inputs their row and column. Once input if the seat is available then it will have a message appear saying thanks for selecting row column but if it is unavailable then it would say seat taken choose another. Also once a seat is taken I need to display an X in the array to show that it is taken.
I'm currently trying to move my array into a function but every time I do it no longer runs. Please help any advice would be much 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
 #include <iostream>

using namespace std;

void display_array(int seatingArray[9][8]);

void check_seating(int seatingArray[9][8], int userRow, int userColumn, bool&
seatTaken);

bool theater_full(int seatingArray[9][8]);

int main()
{
     int seatingArray[9][8] ={
{ 40, 50, 50, 50, 50, 50, 50, 40 },
{ 30, 30, 40, 50, 50, 40, 30, 30 },
{ 20, 30, 30, 40, 40, 30, 30, 20 },
{ 10, 20, 20, 20, 20, 20, 20, 10 },
{ 10, 20, 20, 20, 20, 20, 20, 10 },
{ 10, 20, 20, 20, 20, 20, 20, 10 },
{ 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 10, 10, 10, 10, 10 } };

for(int i=0; i<9; i++)    //This loops on the rows.
	{
		for(int j=0; j<8; j++) //This loops on the columns
		{
			cout << seatingArray[i][j]  << "  ";
		}
		cout << endl;
	}

return 0;
}
@azehm628

Not sure what your numbers mean in the array, but here is a way to display your array in the function and place the 'X' at a chosen location. Place a zero in the location the user picks for a seat. If the array location was already a zero, then inform that the seat is already taken, and to choose again. If you're wanting an actual 'X' in the array, you're going to need to change your array definition from an int to a char and fill with '?'.
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
#include <iostream>

using namespace std;

void display_array(int seatingArray[9][8]);

void check_seating(int seatingArray[9][8], int userRow, int userColumn, bool&
	seatTaken);

bool theater_full(int seatingArray[9][8]);

int main()
{
	int seatingArray[9][8] = {
		{ 40, 50, 50, 50,  0, 50, 50, 40 },
		{ 30, 30, 40, 50, 50, 40, 30, 30 },
		{ 20, 30, 30, 40, 40, 30, 30, 20 },
		{ 10, 20, 20, 20, 20, 20, 20, 10 },
		{ 10, 20, 20, 20, 20, 20, 20, 10 },
		{ 10, 20, 20, 20, 20, 20, 20, 10 },
		{ 10, 10, 10, 10, 10, 10, 10, 10 },
		{ 10,  0, 10, 10,  10, 10, 10, 10 },
		{ 10, 10, 10, 10, 10, 10, 10, 10 }
	};

	display_array(seatingArray);

}

void display_array(int seatingArray[9][8])
{

	for (int i = 0; i < 9; i++)    //This loops on the rows.
	{
		for (int j = 0; j < 8; j++) //This loops on the columns
		{
			if (seatingArray[i][j] == 0)
				cout << " X" << "  ";
			else
				cout << seatingArray[i][j] << "  ";
		}
		cout << endl;
	}
}
closed account (Eb09LyTq)
Ahh thanks for clearing that up. I was putting the array in the function as well. I didn't know the function had to stay with in main. The numbers represent seating prices in the array.

I know I need to use a while loop to check to see if the seats are available but how would I implement that. I feel over whelmed and never know where to begin.
Last edited on
@azehm628
Use this function, instead.

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
void display_array(int seatingArray[9][8])
{
	int row,col;
	do{
	for (int i = 0; i < 9; i++)    //This loops on the rows.
	{
		for (int j = 0; j < 8; j++) //This loops on the columns
		{
			if (seatingArray[i][j] == 0)
				cout << " X" << "  ";
			else
				cout << seatingArray[i][j] << "  ";
		}
		cout << endl;
	}
	
		cout << endl << "Which seat would you like? " << endl << "Entering a zero, ends the program.." << endl;
		cout << "Enter the desired row.. (1 to 9)";
		cin >> row;
		if (row>0 && row < 10)
		{
			cout << "Which seat in row " << row << "?.. (1 to 8)";
			cin >> col;
			if (seatingArray[row - 1][col - 1] != 0)
			{
				cout << "That's a fine seat. Cost is $" << seatingArray[row - 1][col - 1] << endl << endl;
				seatingArray[row - 1][col - 1] = 0;
			}
			else
				cout << "Sorry, that seat is NOT available." << endl << "Please choose another.." << endl;
		}
	} while (row != 0);

	cout << endl << "Program ending!!" << endl;
}
closed account (Eb09LyTq)
Wow, that's amazing. I'm really grateful for all of your help. I really want to understand programming (or at least C++) but I always seem to have a problem trying to figure out the inter workings of it. Like I have a general idea of what I need to accomplish but not exactly how to do it.

If I wanted to have a line appear that the theater is all sold out would I add to this function? Or should I start a new one?

Wouldn't I just add another if statement in between lines 24 and 29?
Last edited on
Wouldn't I just add another if statement in between lines 24 and 29?


No. You could create a bool variable, and set it to true. In the loops that print out the array, check if it holds a non-zero amount, and if it does, set the bool to false. At the end of the loops, if the bool is still true, then all seats are taken, and you cout that fact. See what you can come up with, and we'll go from there.
closed account (Eb09LyTq)
Sorry for the delay I had a Physics test I had to take earlier today and had to shift focus. I refined some of my code with my C++ professor and this is what I have currently working for me. So if i wanted to check to see if all of the seats were sold out I would check the display array for everything equaling zero and when that's true then the message saying the theater was sold out would pop up?
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>

using namespace std;

void display_array(int seatingArray[9][8]);

void check_seating(int seatingArray[9][8], int userRow, int userColumn, bool&
seatTaken);

bool theater_full(int seatingArray[9][8]);

int main()
{

    cout << endl << "         Theater Seating Program" << endl << endl;

     int seatingArray[9][8]
      ={
        { 40, 50, 50, 50, 50, 50, 50, 40 },
        { 30, 30, 40, 50, 50, 40, 30, 30 },
        { 20, 30, 30, 40, 40, 30, 30, 20 },
        { 10, 20, 20, 20, 20, 20, 20, 10 },
        { 10, 20, 20, 20, 20, 20, 20, 10 },
        { 10, 20, 20, 20, 20, 20, 20, 10 },
        { 10, 10, 10, 10, 10, 10, 10, 10 },
        { 10, 10, 10, 10, 10, 10, 10, 10 },
        { 10, 10, 10, 10, 10, 10, 10, 10 }
        };

    display_array(seatingArray);

}


void display_array(int seatingArray[9][8])
{
	int row,column;
do{
	for(int i = 8; i > -1; i--)    //This loops on the rows.
	{
		for(int j = 0; j < 8; j++) //This loops on the columns
		{
			if(seatingArray[i][j] == -1)
				cout << "   X ";
			else
				cout << "  $" << seatingArray[i][j];
		}
		cout << endl;
	}

    cout << endl << "Which seat would you like? " << endl
	<< endl << "Entering a -1 ends the program.." << endl << endl;
	cout << "Please select your row ";
	cin >> row;

	if(row > 0 && row < 9)
	{
		cout << endl << "Please select your column ";
		cin >> column;

		if(seatingArray[row - 1][column - 1] != -1)
		{
			cout << endl << "Thank you for choosing seat #"
			<< row << ":" << column << ". Your ticket price is $"
			<< seatingArray[row - 1][column - 1] << endl << endl;

			seatingArray[row - 1][column - 1] = -1;
		}
		else

			cout << endl << "Sorry, that seat is NOT available." 
                        << endl << endl << "Please choose another.." << endl << endl;
	}

} while (row != -1);

	cout << endl << "Program ending" << endl;
}
@azehm628

Replace
1
2
3
4
5
6
7
8
9
10
11
12
13
int row,column;
do{
	for(int i = 8; i > -1; i--)    //This loops on the rows.
	{
		for(int j = 0; j < 8; j++) //This loops on the columns
		{
			if(seatingArray[i][j] == -1)
				cout << "   X ";
			else
				cout << "  $" << seatingArray[i][j];
		}
		cout << endl;
	}


with this, to check for a full theatre seating.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int row, column;
bool full;
do{
	full = true;
	for (int i = 0; i < 9; i++)    //This loops on the rows.
	{
		for (int j = 0; j < 8; j++) //This loops on the columns
		{
			if (seatingArray[i][j] != -1)
				full = false;
			if (seatingArray[i][j] == -1)
				cout << "   X   ";
			else
				cout << "  $" << seatingArray[i][j] << "  ";
		}
	cout << endl;
	}
	if (full)
	{
		cout << "Sorry. Theatre seating is at full capacity.." << endl;
		row = 0;
	}
else
Topic archived. No new replies allowed.