movie theater seating

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

void seats( double [] , int);
void mapSeats();

int main()
{
	const int rowNum = 20;
	double rowValue[rowNum]; //array to hold row pices
	char selection;
	int row2, col2;
	const char TAKEN = '#';//seats taken
	const char EMPTY = '*';//seats free
	const int row = 20;//number of rows
	const int col = 15;//number of col
	char map[row][col];//array to hold seat chart 


	
	for(int i= 0;i<row;i++)//initiating array 
	{
		for (int j=0;j<col;j++)
		{
			map[i][j]=EMPTY;
		}
	}

	mapSeats();

	seats(rowValue, rowNum);//ask user to enter price of each row
	cout << endl;
	
	do
		{
			cout << "MOVIE THEATER MENU" << endl;
			cout << "------------------" << endl;
			cout << "1) Sell a ticket" << endl;
			cout << "2) Total sell and exit" << endl;
			cout << "Please make a selection: ";
			cin >> selection;
			
			if(selection =='1')
			{
				cout << "Please enter a row number and a seat number for the ticket: " ;
				cout << "Row # :" ;
				cin >> row2;
				cout << endl;
				cout << "Seat # :" ;
				cin >> col2;
				cout << endl;

				// Check if seat is free
			if(map[row2][col2] == TAKEN)
			{
				cout << "This seat is taken! Try another one. \n";
				continue; // start the loop again
			}
			else // and if it is - sell the ticket
				map[row2][col2]=TAKEN;
			// Add the next loop to immediately see the effects:
			for (int i = 0; i < row; i++)
			{
				for(int j = 0; j < col; j++)
				{
					cout << map[i][j];
				}
				cout << endl;
			}


			}
			else if(selection =='2')
			{
				cout << "TOTAL TICKETS SOLD: " << endl;
				cout << "TOTAL REVENUE: ";
			}
			else if(selection != '1' || selection !='q' || selection !='Q')
			{
				cout << "Invalid selection." << endl;
			}
		}while(selection != '1' || selection !='q' || selection !='Q');
	

	system("PAUSE");
	return 0;
}


void seats(double rowPrice[], int row)
{
	int sum;
	cout << "Please enter a ticket price for each row." << endl;
	
	for(int i = 0 ; i < row; i++)
	{
		cout << "Row # " << i+1 << ": " ;
		cin >> rowPrice[i];	
	}
}

void mapSeats()
{
	const char TAKEN = '#';//seats taken
	const char EMPTY = '*';//seats free
	const int rw=20;
	const int cl=15;

	cout << "Seats " ;
	for(int k = 0 ; k <15;k++) //loop to display nums 0 to 14
	{
		cout << fixed<< setw(2) << " " << k ;
	}

	for(int i=0;i<rw;i++)//making array display what's in it
	{
		cout << endl<< "Row " << i;
		for(int j=0;j<cl;j++)
		{
			cout << fixed<< setw(2) << "" << EMPTY;
		}
	}
	cout << endl;
}


// I am trying to produce the total number of tickets sold and the total revenue from all tickets sold to be displayed at menu option (2), but i can't figure out how. can someone show me how please?
Last edited on
1) Look at the conditions on lines 79 ad 83. Under what circumstances would you expect that condition to be false?

2) To answer your question, you want to keep a running total of the number of seats sold, and the revenue. Each time a ticket is sold, update those two values. When the user selects option 2, print those values out.
Topic archived. No new replies allowed.