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
|
//Purpose: Displays a ticket pricing 2D array
#include <iostream>
#include <iomanip>
using namespace std;
const int row = 9; //sets a global variable for number of rows
const int col = 10; //sets a global variable for number of columns
//function displays the current seating chart
void seat_display(int seats[row][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 select;
int seats[row][col] = //sets the seating chart
{
{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 },
};
do
{
do
{
seat_display(seats); //displays the seating chart to user
select = select_seat();
if (select == 1)//user enters a seat number
{
int i = 0;
int j = 0;
int rownumber; //for row
int colnumber; //for column
cout << "Please enter the row you would like to sit in: ";
cin >> rownumber;
if (rownumber >= 0 && rownumber < 9)
{
cout << "Please enter the seat you would like to sit in: ";
cin >> colnumber;
system("cls");
if (colnumber >= 0 && colnumber < 10)
{
if (seats[rownumber][colnumber] != 0)
{
cout << "You have selected seat "<<rownumber<< ", " <<colnumber<< "."<<endl;
cout << "The cost of that seat is "<<seats[rownumber][colnumber] <<endl;
seats[rownumber][colnumber] = 0;
}
else
{
cout << "That seat is taken."<<endl;
}
}
}
}
else if (select == 2) //user enters a price
{
int seatprice; //variable that stores the price of the seat
int i = 8;
int j = 9;
bool found = false;
cout << "Please enter a seat price: ";
cin >> seatprice;
system("cls");
while (i >= 0 && !found)
{
j = 9;
while (j >= 0 && !found)
{
if (seats[i][j] == seatprice)
{
cout << "you are sitting in row " << i << ", column " << j << "." <<endl;
seats[i][j] = 0;
found = true;
}
j--;
}
i--;
}
if (!found)
{
cout << "All seats at this price are taken."<<endl;
}
}
else if (select == 3) //exits program
{
exit(0);
}
else if (select > 3 || select < 1)
{
cout<<"Please enter 1, 2, or 3."<<endl; //if user enters an invalid input
}//select = -1; //they are reprompted
} while (select!= 3);
} while (select > 3 || select < 1);
}
|