Understanding pointers and using them in a function

I am having a hard time with this. I need help with how to use pointers and if you could show me what I;m doin wrong I made an airplane seating chart and I want to use pointers in dynamic arrays. So I took the code that I first made and just changed it a little but now I am getting errors and I don't know how to solve it. The program asks how many rows are in the airplane and then displays the seating chart. Should ask the user what seat and row he'd like to sit in. Then it will mark that seat with an 'x'. If the seat is taken it should say the seat is taken. And then display the available seats. It will keep going until the user says he wants to quit or until there is no more seats left. What I'm having a hard time with is my second function. If you can show me what to do it would be greatly appreciated. This is my code that i have so far.The display seating works But the chooseseats function doesn't.


//Airplane seating

#include <iostream>
#include <cmath>
using namespace std;
typedef char* charArray;

typedef charArray* char2Array;

void display_seating(char2Array a, int rows, int seats);
void choose_seats(char2Array a, int& input_row, char& input_seat, int rows, int seats);

int main()
{


int input_row;
char input_seat, response;
int row,col;
int rows, seats;

cout << "Rows in the plane:";
cin >> rows;

cout << "Seats in each row:";
cin >> seats;

charArray *seat = new charArray[rows];

for(row = 0; row < rows; row++)
seat[row] = new char[seats];


for(row = 0; row < rows; row++)

for(col = 0; col < seats; col++)
seat[row][col] = static_cast<char>(toupper('A') + col);
display_seating(seat,rows,seats);
/* This do/while is for going through the seats that are available until they are all choosen*/
do
{
choose_seats(seat,input_row, input_seat, rows, seats);
display_seating(seat,rows,seats);
cout << "Would you like to keep going(Y or y): ";
cin >> response;
}while(response == 'Y' || response == 'y');
return 0;
}


// This function is for displaying the available seats
void display_seating(char2Array a, int rows, int seats)
{
for(int row = 0; row < rows; row++)
{
cout << row + 1 << " ";

for(int col = 0; col < seats; col++)
{
cout << a[row][col] << " ";
}

cout << endl;
}
}

// This is the function i'm haviing a hard time with
/* This function asks the user to choose his seat. If the seat is not a valid seat it will say no a valid seat and ask you to choose again. If the seat is you choose is already taken it says taken and asks for your seat again. If its not taken it will mark that seat with an 'x'.*/
void choose_seats(char2Array a, int& input_row, char& input_seat, int rows, int seats)
{
int col;
char response;
do
{
do
{
cout << "Which row would you like to sit in: ";
cin >> input_row;
cout << endl;
cout << "Which seat would you like to sit in: ";
cin >> input_seat;
cout << endl;
cout << "Is this the seat that you want. ";
cin >> response;
cout << endl << endl;

while(input_row > rows || input_row < 1)
{
cout<< "Invalid Seat" << endl;
cout << "Enter your seat again: ";
cin >> input_row;
}
input_row--;

cout << "Enter the seat that you want from A-D: ";
cin >> input_seat;
input_seat = toupper(input_seat);
col = toupper(input_seat) - toupper('A');
while(col >= seats || col < 0)
{
cout << "Invalid Seat:" << endl;
cout << "Enter the Seat you want: ";
cin >> input_seat;
input_seat = toupper(input_seat);
col = input_seat - 'A';
}
if(a[input_row][col] == 'X')
{
cout << "I'm sorry that seat is already taken.\n";
cout << "Please try another seat.\n";

}while(a[input_row][col] == 'X');


}while(response == 'N' || response == 'n');
a[input_row][col] = 'X';
}
In choose_seats function - your { and } don't match up.
You are missing a }

I'll leave you to find out where.
Topic archived. No new replies allowed.