Need Help With Some Coding

I have a program I am supposed to be making for class and I am really stuck. I have to display an array and get a seating input of a column and row. I posted that code below.

int Row,Col;


cout << "Please select a Theater Seat Row : " ;
cin >> Row;


cout << "Please select a Theater Seat Column : " ;
cin >> Col;
cout << endl;


Now after this i have to display the array and have it output an "X" where the column and row chosen are. The code for my array is posted below.


int seating_array[9][8] ={
{ 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 } };


for (int i=0; i < 9;i++){
for (int j=0; j<8;j++){
std::cout << " " << "$" << seating_array[i][j] <<' ';
}
std :: cout << std :: endl;
}


Can anyone give me any suggestions on how to do this with the code I have?
Last edited on
If i equals Row AND j equals Col you should output an 'X' - right? Where should you put that pseudocode?
Before the code that prints the array?
Try it out and let us know what happens =D
So this is the code i put and now it prints out the array with an X but it also includes the number of the seat as well, how would I get rid of that?


for (int i=0; i < 9;i++){
for (int j=0; j<8;j++){
if (i==Row && j==Col){
std ::cout<<" "<<"X"<<seating_array[Col][Row]<<' ';
}
std::cout << " " << "$" << seating_array[i][j] <<' ';
}
std :: cout << std :: endl;
}

}
As far as I can tell it doesn't include the number of the seat but rather the price of it.

The line :
std::cout << " " << "X" << seating_array[Col][Row] << ' ';
is the offender. What does seating_array[Col][Row] represent? Is it something you want to output?
The price of the seat is what i want to replace with an x to show that it has been taken already. My program is supposed to loop every time that someone chooses a seat and replace the chosen seat with an x.
So far this is the code i have for the program

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

void display_seating(int seating_array[9][8]);
void ask_seats(int &Col,int &Row);
void seating_available(int seating_array[9][8],int Col,int Row);

using namespace std;

int main(){

int Col = 0;
int Row = 0;
int seating_array[9][8] ={
{ 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 } };


display_seating(seating_array);
ask_seats(Col,Row);
seating_available(seating_array,Col,Row);

return 0;
}

//display seating chart

void display_seating(int seating_array[9][8]){

cout << " -Available Theater Seating-\n\n";

for (int i=0; i < 9;i++){
for (int j=0; j<8;j++){
std::cout << " " << "$" << seating_array[i][j] <<' ';
}
std :: cout << std :: endl;
}
cout << endl;

}

void ask_seats(int &Col,int &Row){
//Loop to ask for seating

if (Col < 10 && Row <9){

cout << "Please select a Theater Seat Row : ";
cin >> Row;

cout << "Please select a Theater Seat Column : ";
cin >> Col;
cout << endl;

//Validate seating choice
while (Col > 9 || Row >8){

cout << "ATTENTION: That seat is not available \n Please choose another\n\n";

cout << "Please select a Theater Seat Row : ";
cin >> Row;

cout << "Please select a Theater Seat Column : ";
cin >> Col;
cout << endl;

}
}

}

//Print out "X" for chosen seat

void seating_available(int seating_array[9][8],int Col,int Row){



for (int i=0; i < 9;i++){
for (int j=0; j<8;j++){
if (i==Row && j==Col){
std ::cout<<" "<<"X"<< seating_array[i][j]<<' ';
}
std::cout << " " << "$" << seating_array[i][j] <<' ';
}
std :: cout << std :: endl;
}

}
Topic archived. No new replies allowed.