Write a program that prompts users to pick either a seat or a price. Mark sold seats by changing the
price to -1. When a user specifies a seat (11 = first row first col (shown in bold on seating plan)), make
sure it is valid and available. When a user specifies a price, find any seat with that price. User should
enter -99 to exit.
#include <iostream>
#include <string>
using namespace std;
int main() {
int seatPrices[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 },
{ 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 },
};
int ch=-1;
int seatRow;
int seatCol;
int price;
do{
cout<<"Pick by Seat <1> or Price <2> or Quit <-99>: ";
cin>>ch;
if(ch==1){
do{
cout<<"Enter row seat [1-10]: ";
cin>>seatRow;
}while(seatRow<1 || seatRow>10);
do{
cout<<"Enter column seat [1-10]: ";
cin>>seatCol;
}while(seatCol<1 || seatCol>10);
if(seatPrices[seatRow-1][seatCol-1]!=-1){
cout<<"The seat price is: "<<seatPrices[seatRow-1][seatCol-1]<<"\n\n";
seatPrices[seatRow-1][seatCol-1]=-1;
}else{
cout<<"The seat is sold\n\n";
}
}else if(ch==2){
do{
cout<<"Enter seat price [10-50]: ";
cin>>price;
}while(price<10 || price>50);
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
if(price==seatPrices[i][j] && seatPrices[i][j]!=-1){
cout<<"The seat with that price is: row: "<<(i+1)<<", column: "<<(j+1)<<"\n";
seatPrices[i][j]=-1;
i=100;
j=100;
}
}
}
cout<<"\n\n";
}else if(ch==-99){
//exit
}
}while(ch!=-99);
return 0;
}
Comments
Leave a comment