123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
#include <iostream> #include <cstdlib> #include <ctime> # include <iomanip> using namespace std; int main(); void Menu(); int SeatSelection(); void DisplaySeating(); int main() { // Seed the random number generator srand(time(0)); Menu(); return 0; } // Menu so can keep playing or close the program void Menu() { int selection = 0; bool Selecting = true; while (Selecting) { cout << "Theatre Seatting\n\n"; cout << "Menu\n\n"; cout << "1) Sell Ticket\n"; cout << "2) Exit\n\n"; cout << "Enter your selection: "; cin >> selection; cin.ignore(); cout << endl; if (selection == 1) SeatSelection(); else if (selection == 2) Selecting = false; else if (selection != 1 || 2) //lets the user know why they are going back to the menu cout << "Try again, choose 1 or 2" << endl; } } int SeatSelection() { const int rows = 12; const int columns = 8; int TotalSeats = 96; int selection; double RowValue[rows]; char map[rows][columns]; int RowNum, ColNum; const char Taken = '#';//seats taken const char Empty = '*';//seats free for(int i= 0;i<rows;i++)//initiating array { for (int j=0;j<columns;j++) { map[i][j]=Empty; } } DisplaySeating(); (RowValue);//ask user to enter price of each row cout << endl; cout << "Seat Selection Menu\n"; while (true) { cout << "You have " << TotalSeats << " seats remaining\n\n"; // so the user can keep track of seats left cout << "Please enter a row number and a seat number for the ticket: " ; cout << "Row # :" ; cin >> RowNum; cout << endl; cout << "Seat # :" ; cin >> ColNum; cout << endl; cin.ignore(); // Check if seat is free if(map[rows][columns] == Taken) { cout << "This seat is taken! Try another one. \n"; continue; // start the loop again } else // and if it is - sell the ticket map[rows][columns]=Taken; // Add the next loop to immediately see the effects: for (int i = 0; i < rows; i++){ for (int j = 0; j < columns; j++){ cout << map[i][j]; } cout << endl; } cout << '\n'; if (selection == Taken) { cout << "Sorry, that seat is taken: " << RowNum, ColNum; "Please select another seat"; cin.get(); cout << "\n\n"; return (0); } else if (selection == Empty) { cout << "Thank you for your purchase" << endl; cin.get(); cout << "\n\n"; } TotalSeats--; if (TotalSeats == 0) { cout << "Sorry, we are sold out " << endl; cout << "\n"; return (0); } } } void seats(double RowPrice[], int row) { cout << "Please enter a ticket price for each row." << endl; for(int i = 0 ; i < row; i++) { cout << "Row # " << i++ << ": " ; cin >> RowPrice[i]; } } void DisplaySeating() { const char TAKEN = '#';//seats taken const char EMPTY = '*';//seats free const int rows = 12; const int columns = 8; cout << "Seats " ; for(int k = 0 ; k < 12; k++) //loop to display nums 0 to 12 { cout << fixed<< setw(2) << " " << k ; } for (int i = 0; i < rows; i++)//making array display what's in it { cout << endl<< "Row " << i; for (int j = 0;j < columns; j++) { cout << setw(3) << "" << EMPTY; } } cout << endl; }