how to solve this?

this is new solved and complete program .


#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <windows.h>

using namespace std;

const int rows = 9;
const int cols = 8;
int userRow;
int userCol;
int total = 0;

void display_seating(int seatingArray[rows][cols]); // display seating area
void get_validinput(int seatingArray[rows][cols],int& userRow, int& userCol, int& total); // show appropriate output and comments // output sold out

int main()
{
int seatingArray[9][8] ={ // array for seats
{ 40, 50, 50, 50, 50, 50, 50, 40 },
{ 30, 30, 40, 50, 50, 40, 30, 30 },
{ 20, 30, 30, 40, 40, 30, 30, 20 },
{ 10, 20, 20, 20, 20, 20, 20, 10 },
{ 10, 20, 20, 20, 20, 20, 20, 10 },
{ 10, 20, 20, 20, 20, 20, 20, 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 } };

if(total != 72) // theater is not sold out
{while (total != 72)
{display_seating(seatingArray); // function recall for display seating area
get_validinput(seatingArray,userRow, userCol, total); // user input and validate input and show appropriate output
}}
display_seating(seatingArray);
cout<<endl; // theater sold out
cout << "ATTATION: THE theater has been sold out."<<endl;

return 0;
}

void display_seating(int seatingArray[rows][cols]) // function definition
{
cout<<" Available Theater Seating"<<endl; // output heading
cout<<endl;
for(int rows=0; rows < 9; rows++)
{
for(int cols=0; cols < 8; cols++)
{if(seatingArray[rows][cols] == false)
cout<< " X ";
else
cout<<" "<<"$"<< seatingArray[rows][cols]<<" ";} // output seats with $ sign
cout<<endl;
}
}

void get_validinput(int seatingArray[rows][cols],int& userRow, int& userCol, int& total) // selecting seat
{
cout<<"Please enter theater seat row: "; // getting input from user for seat
cin>> userRow;
cout<<"Please enter theater seat column: ";
cin>> userCol;

while(userRow>9 || userCol>8 || userRow <=0 || userCol<= 0 || (seatingArray[userRow-1][userCol-1] == false) ) // validate the input
{ if(userRow>9 || userCol>8 || userRow <=0 || userCol<= 0)
{
cout<<"ATTATION: THE SEAT SELECTED "<<userRow<<":"<<userCol<<" DOSE NOT EXIST."<<endl;}
else if(seatingArray[userRow-1][userCol-1] == false) // output appropriate error
{
cout<<"ATTATION: the seat has already been sold.";
cout<<" choose different seat."<<endl;
}
cout<<"Please enter theater seat row: "; // getting input from user for seat
cin>> userRow; //if its wrong first time or seat is selected
cout<<"Please enter theater seat column: ";
cin>> userCol;
}

cout<< "Thank you for choosing "<<userRow<<":"<<userCol<<endl; // output seat number
cout<<"your ticket price is:$ "<<seatingArray[userRow-1][userCol-1]<<endl; // output price
Sleep(1500);
system("CLS");
total += 1;
seatingArray[userRow-1][userCol-1] = false ; // stop and start again
}
Last edited on
What do these numbers mean?
1
2
3
4
5
6
7
8
9
10
int seatingArray[9][8] ={ // array for seats
{ 40, 50, 50, 50, 50, 50, 50, 40 },
{ 30, 30, 40, 50, 50, 40, 30, 30 },
{ 20, 30, 30, 40, 40, 30, 30, 20 },
{ 10, 20, 20, 20, 20, 20, 20, 10 },
{ 10, 20, 20, 20, 20, 20, 20, 10 },
{ 10, 20, 20, 20, 20, 20, 20, 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 } };
@Unkana wrote

What do these numbers mean?


By looking at the code..
1
2
cout<< "Thank you for choosing "<<userRow<<":"<<userCol<<endl; // output seat number
cout<<"your ticket price is:$ "<<seatingArray[userRow-1][userCol-1]<<endl; // output price 

you can see that the numbers in the array, represent the cost for that row/column location.
Numbers are the price for tickets
When I run the program I am getting 0 in seat I select instead of X ....
I don't know how to stop the loop when seats are sold out ....
Last edited on
You're trying to use seatingArray in inconsistent ways.
Line 30:
 
while (seatingArray[userRow-1][userCol-1] != EMPTY)

You're trying to compare a ticket price (int) against the character 'X'. ASCII X has the decimal value of 88. C++ lets you do that, but it's poor style. It presumes you would never price a seat as $88.

Line 58,62,77:
 
while(userRow>9 || userCol>8 || userRow <=0 || userCol<= 0 || (seatingArray[userRow-1][userCol-1] == false) )

You're trying to compare a seat against a boolean constant. Again, you're mixing types. Not a good idea. Here again C++ allows you to do this. You're effectively comparing the ticket price to 0.

When I run the program I am getting 0

That's because you're storing false (0) in the seat.

I don't know how to stop the loop when seats are sold out

Count the number of seats sold. When the count reaches rows*cols, you're sold out and you should exit the loop.

I don't know how to get "X"

At line 46 where you display the price, you need to test if the seat has been sold. If it has, then you want to display 'X' instead of the ticket price.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.



Last edited on
Got it....
Thanks for your help....
I got it working.....
Topic archived. No new replies allowed.