Theater Seating c++ error

In the following code, when I would select View Menu Prices, Purchase Tickets, and Sales Statistics the wrong price would display. For example if tickets in row 1 cost $1 the compiler would display 4716832. There is no syntax error because the code runs in a compiler, but doesn't display the correct price. Any ideas on whats causing this and how to fix it. My complete code below.

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
 #include <iostream>
    #include <iomanip>
    #include <fstream>
    #include <conio.h>
    using namespace std;

//function prototypes

    int menu();                    
    void Seating_Chart();               
    void seatingChartRow(int);
    void seating_prices();
    void buy_tickets();
    


    const char TAKEN = '*';                     //shows seat taken
    const char EMPTY = '#';                     //shows seat available
    const int ROWS = 15;                         //number of rows in theater
    const int COLUMNS = 10;                     //number of seats per row in theater
    char seating [ROWS][COLUMNS];               //array to hold seating chart
    double price;
    int total = 0;
    int ticketSales;
    int quit;

//main function

    int main()
    {

    const int NUM_ROWS = 10;
    int price [NUM_ROWS];
    int rowChoice;                          //choice of row
    int seatChoice;                         //choice of seat
    int cost;                               //cost of ticket
    int confirm;                            //purchase confirmation


    //set prices for each row
    for(int count=0; count<ROWS; count++)
    {
      cout <<"Enter the price for row " << (count+1) <<": $";
      cin >> price[count];
    }

    for(int x= 0; x<ROWS; x++)
    {
    for(int y=0; y<COLUMNS; y++)
    
       seating [x][y] = EMPTY;
    }

    int choice;

    do
    {
        Seating_Chart();
        choice = menu();

        switch(choice)
        {

        case 1: seating_prices();
                break;

        case 2: buy_tickets();
                break;

       
        case 3: saleStats();
                break;

        case 4:
            cout <<"Quit\n";
            break;

        default: cout <<"Error Input\n";

        }
    }

    while (choice<5);

    return 0;
    }


    void seating_prices()
    {
      const int NUM_ROWS = 10;
      int price [NUM_ROWS];

      cout <<"Seating Prices\n\n";

      for(int count=0;count<ROWS; count++)
       {

       cout <<"The price for row " << (count+1) <<": $";
       cout <<price[count] <<endl;
       getch();
       }
    }

    void buy_tickets()
    {

    const int NUM_ROWS = 10;

    int price [NUM_ROWS];
    int rowChoice;                          //choice of row
    int seatChoice;                         //choice of seat
    int cost;                               //cost of ticket
    int confirm;
     
    cout <<"Purchase Tickets\n\n";

    do
    {

     cout <<"Please enter the row: ";
     cin >>rowChoice;

     cout <<"Please enter the seat: ";
     cin >>seatChoice;

     if(seating[rowChoice][seatChoice] == '*')
     {
       cout <<"That seat is unavailable please make another selection.\n";
     }

     else
     {
        cost = price[rowChoice] + 0;
        total += cost;

        cout <<"Ticket price: " <<cost <<endl;
        cout <<"Please confirm your purchase.  Enter 1 for yes, 2 for no.";
        cin >>confirm;

     if(confirm==1)
     {
        cout <<"Your ticket purchase has been confirmed.\n";

        seating[rowChoice][seatChoice] = TAKEN;
        ticketSales++;
     }

     else if (confirm==2)
     {
        cout <<"Would you like to purchase another ticket?  Enter 1 for yes, 2 for no." <<endl;
        cin >>quit;
     }

     cout <<"Would you like to purchase another ticket?  Enter 1 for yes, 2 for no.";
     cin >>quit;

    }

    }
    while (quit==1);
    }



    int menu()
    {

    int menuChoice;

    cout <<"\n\n\tMAIN MENU\n";

    cout <<"1. View Seat Prices\n";

    cout <<"2. Purchase Tickets\n";

    cout <<"3. View Seats by Row\n";

    cout <<"4. Sales Statistics\n";

    cout <<"5. QUIT\n";

    cout <<"------------------------\n\n";

    cout <<"Enter your choice: ";

    cin >>menuChoice;

    cout <<endl <<endl;

    return menuChoice;

    }

    void Seating_Chart()
    {
     cout <<"\tSEATING CHART\n";

     cout<<"LEGEND:    # Available Seat    * Unavailable Seat\n";

     cout <<"\t1   2   3   4   5   6   7   8   9   0\n";

     for(int x= 1; x< ROWS; x++)
     {
      cout <<"Row " <<(x);

         for(int y= 0;y<10; y++)
         {
           cout << setw(4) <<seating[x][y];
         }

      cout <<endl;

    }

    }

    void seatingChartRow(int)
    {
        cout <<"\tSEATING CHART\n";

        cout<<"LEGEND:    # Available Seat    * Unavailable Seat\n";

        cout <<"\t1   2   3   4   5   6   7   8   9   0\n";

        for(int x= 0; x< ROWS; x++)
        {
         cout <<"Row " <<(x+1);

        for(int y= 0; y< COLUMNS; y++)

        {
            cout << setw(4) <<seating[x][y];
        }

        cout <<endl;

    }

    }
int price[NUM_ROWS]; is local variable in every function.
When you ask user for prices in main(), you set only local variable in main(), but not in buy_tickets() or seating_prices(). So in other functions these variables have same names but different values (trash because uninitialized).
Make it global, define it somewhere between 16-26 lines and remove from other places.
Topic archived. No new replies allowed.