help with program

anyone know how to fix this code? I can't seem to figure it out, and its due tonight! can anyone help?

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  #include <iostream>
#include <windows.h>
#include <cstdlib>

using namespace std;

void display_array (int userRow);

void check_seating (int userRow, int userColumn);

bool theater_full ();

int main()
{
    int userRow, userColumn;

    display_array (userRow);
    check_seating (userRow, userColumn);
    theater_full ();

}


void display_array (int userRow)
{
     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 }
        };

        cout << endl << "Which seat would you like? " << endl;

	cout << "Please select your row ";
	cin >> userRow;
}


void check_seating (int userRow, int userColumn)
{

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

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

			seatingArray[userRow - 1][userColumn - 1] = -1;

			Sleep(1000);
			system("CLS");
			cout << endl << "         Theater Seating Program" << endl << endl;
		}
		else
        {


			cout << "Sorry, that seat is NOT available." << endl;
            cout << "Please choose another.." << endl << endl;
            Sleep (1000);
            system("CLS");
            cout << endl << "         Theater Seating Program" << endl << endl;
	}

} while (userRow != -1);

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


bool theater_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;
		userRow = 0;
	}

First of all, what error does the compiler return?
I think the problem is the fact that you declare the variable seatingArray locally in your display_array function. Your other functions seem to use the variable, but they don't have access to it. Declaring the variable globally should solve that problem.

Your last function seems to have a few syntax errors too. First of all I'd remove the "do" in the theater_full function. And then add another closing bracket at the end of the function.

A third problem I noticed just now is how you're reading from cin in your display_array function. You're reading from cin and storing the value in a function parameter, but since it's passed by value the read value is not stored in the variable you passed, but in a copy of it, which will be destroyed at the end of the function. You can solve this by passing the variable by reference. The new function definition would then become void display_array (int& userRow)
Last edited on
Topic archived. No new replies allowed.