Two Dimensional Arrays.

I have to write a program that displays ticket prices to users in a 9x10 grid.
The user is then asked to pick a seat or pick a price. They also have the option to exit the program.

When a seat is taken, the price is set to 0 and the user is no longer able to pick that seat in the future. If the user specifies a price (10,20,30,40 or 50), the program finds any seat at that price, starting from the front of the theatre, then working back (front is the last row).


Here is what I have so far

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
//Purpose: Displays a ticket pricing 2D array

#include <iostream>
#include <iomanip>

using namespace std;
const int row = 9;
const int col = 10;

//function displays the current seating chart
void seat_display(int seats[][col])
{
	
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < col; j++)
		{
			cout<< setw(7) << seats[i][j];
		}
		cout<< endl;
		cout<< endl;
	}
}
//function allows user to pick a seat number, enter a price, or quit the program
int select_seat()
{
	int select;
	cout << "Press 1 to enter seat number, 2 to enter a price, or 3 to quit: ";
	cin >> select;
	return select;
}


int main()

int seats[row][col] = 
{
	{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, 10, 10, 10, 10, 10},
	{10, 10, 20, 20, 20, 20, 20, 20, 10, 10},
	{10, 10, 20, 20, 20, 20, 20, 20, 10, 10},
	{10, 10, 20, 20, 20, 20, 20, 20, 10, 10},
	{20, 20, 30, 30, 40, 40, 30, 30, 20, 20},
	{20, 30, 30, 40, 50, 50, 40, 30, 30, 20},
	{30, 40, 50, 50, 50, 50, 50, 50, 40, 30}
};
 

	{
		seat_display();
		select = select_seat();
		do
		{
			if (select == 1)//user enters a seat number
			{




			}
			else //select is 2 because it is not 1 or 3, user enters a price
			{


			}
		} while (select !=3)
	}
}



Here is what I currently am having trouble with:

1
2
3
do
		{
			if (select == 1)//user enters a seat number 


I don't know what to type in to have the user pick a seat number. The text isn't helping. I'm assuming I should start with something like cout<<"Please enter a seat number"; but after that I'm not exactly sure on how to let the user do that.

Any help/links to help much appreciated.

Thanks.
A seat number is usually in the form A1, where A is the row and 1 is the column.
You can read it as a string then divide the letter from the number and converting the two values in an array position
For ease I'm going to make what would be seat A1 into seat 0,0.

So for the first selection I need the user to enter a seat number.

Should I ask the user to input two ints (one for row and one for column), or can I get the info in the 2d-array format (IE: user would just enter 0,0 when prompted to pick seat)?
You can use cin >> int >> char >> int so that the two ints would read the number, the char skips the comma
Topic archived. No new replies allowed.