theater ticket program(input file and array help)

My program uses a 2D array(15x20) to simulate a theater and asks the user which seat they wish to buy. '*' denotes empty seat and '#' denotes taken seat. The prices vary by each row and the prices come from an input file. When the user quits the program, it tallies the total sales from the tickets and i don't know how to do that.

prices from input file: $10(rows 0 - 4), $9(row 5 - 9), and $8(rows 10 - 14)




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
  #include <iostream>
#include <cctype>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

const int rowNum = 15;
const int colNum = 20;
const char available = '*';
const char taken = '#';
void displayTheater(char theater[][20], int rowNum, int colNum);
void getPrices(double prices[]);


int main ()
{
	bool menu = true;
	char choice;
	int row, seat;
	char theater[rowNum][colNum];
	int ticket = 0;
	double prices[15];

	for(int i = 0; i < rowNum; i++)
	{
		for(int j = 0; j < colNum; j++)
		{
			theater[i][j] = available;
		}
	}

	while(menu)
	{
		displayTheater(theater, rowNum, colNum);
		getPrices(prices);
		cout << endl << "Menu:\n";
		cout << "1) Buy Ticket\n";
		cout << "2) Total Sell and exit\n\n";
		cout << "Enter your choice : ";
		cin >> choice;
		cout << endl;

		switch(choice)
		{
		case '1': 
			{
				cout << "Enter row: ";
				cin >> row;
				cout << endl;
				cout << "Enter seat: ";
				cin >> seat;
				cout << endl;

				if(theater[row][seat] = available)
				{
					theater[row][seat] = taken;
					ticket++;	
				}

				else 
				{
					cout << "invalid choice\n";
					//theater[row][seat] = taken;
					//ticket++;
					
				}
				//user can't buy same seat twice(what i was trying to do below but didn't work)
				//if(theater[row][seat] == taken)
				//{
					//cout << "Seat has already been taken, please select another one\n";
					//continue;
				//}

				break;
			}
		case '2':
			{
				menu = false;
				break;
				//this is where the total sales will be displayed
			}
		default:
			{
				cout << "Invalid Choice\n\n";
				break;
			}
		
		}
	
	}
	


	system("PAUSE");
	return 0;
}

void displayTheater(char theater[][20], int rowNum, int colNum)
{
	cout << "* Seats available\n";
	cout << "# Reserved Seats\n";
	cout << "Seats:  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19" <<  endl;



	for(int i = 0; i < rowNum; i++)
	{
		cout << "Row" << setw(3) << i;

		for(int j = 0; j < colNum; j++)
		{
			cout << fixed << setw(2) << " " << theater[i][j];
		}
		cout << endl;
	}
}

void getPrices(double prices[])
{
	ifstream inputFile;
	inputFile.open("prices.txt");

	for(int i = 0; i < 14; i++)
	{
		inputFile >> prices[i];
	}

}
When the user quits the program, it tallies the total sales from the tickets and i don't know how to do that

You need to keep a running tally of the price of the seats sold.

When you sell a seat, figure out the price of that seat, then add the price of the seat to the running tally. At the end of the program, simply display the running tally.

BTW, line 128 you never close the file. This is a resource leak.
Topic archived. No new replies allowed.