ASAP!!!Airplane seating help !!!C++

I just need help in making a "*" change into a "X" when I enter the row and column numbers. I can't use <window.h> due to me having a Mac PLEASE HELP!

MY CODE:


#include <iostream>
#include<fstream>
#include<iostream>
#include<cstring>
#include <string>
#include<array>

using namespace std;

void makeReservation ( int &a, int &b)
{
int beta[a][b];
if ( beta [a][b]=='X')
{
cout<< "Seat is already taken";

}
else if(beta[a][b]=='*')
{
for(int i=0; i<13;i++)
{
for(int j=0;j<6; j++)
{
if( beta [a][b]==beta[i][j])
beta [a][b]='X';
else
beta[i][j] = '*';

}
}
}


}

void displayMap (char matrix[13][6])
{
cout<<"Seats ABCDEF"<<endl;
for(int i=0; i<13;i++)
{

cout << "Row " << (i+1) << " ";
for(int j=0;j<6; j++)
{
cout<< matrix[i][j];
}
cout<<endl;

}

}
int main()
{
char again= ' ';
cout<< "would you like to reserve a seat? (Y/N): ";
cin>> again;

again ='Y';

while(again == 'Y')
{
cout<< "Rows 1-3 are first-class seats" <<endl;
cout<< "Rows 5-13 are economy seats"<<endl;
cout<< "X = seat is occupied"<<endl;
cout<< "* = seat is available"<<endl;
cout<<"_____________________________________________________________________________________________________________"<<endl;
char alpha[13][6];

for(int i=0; i<13;i++)
{
for(int j=0;j<6; j++)
{
alpha[i][j] = '*';
}
}


displayMap(alpha);

int x,y;
cout<< "Which row would you want: ";
cin>> x;
cout<<"Which column would you want:";
cin>>y;

makeReservation (x,y);

cout<< "Enter another seat? (Y/N) ";
cin>> again;
cout<<endl;
cout<<"\n";
}}
Something like this, perhaps:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <iomanip>

const int NROWS = 13 ;
const int NCOLS = 6 ;
const char FREE = '*' ;
const char TAKEN = 'X' ;

bool valid_seat( int a, int b ) { return a >= 0 && a < NROWS && b >= 0 && b < NCOLS ; }

void reserve( char seats[NROWS][NCOLS], int a, int b )
{
    if( !valid_seat(a,b) ) std::cout << "*** error: invalid seat number\n" ;

    else if ( seats[a][b] == TAKEN ) std::cout<< "*** error: seat is already taken\n";

    else seats[a][b] = TAKEN ; // indicate that the seat is now taken
}

void display( const char seats[NROWS][NCOLS] )
{
    std::cout << "Rows 1-3 are first-class seats\n"
              << "Rows 4-" << NROWS << " are economy seats\n"
              << TAKEN << " = seat is occupied\n"
              << FREE << " = seat is available\n"
              << "_____________________________________\n"
              << "Seats  ";
    for( int i = 0 ; i < NCOLS ; ++i ) std::cout << std::setw(3) << i+1 ;
    std::cout << '\n' ;

    for(int i=0; i<NROWS; i++)
    {
        std::cout << "Row " << std::setw(2) << (i+1) << ' ' ;
        for(int j=0; j<NCOLS; j++) std::cout << std::setw(3) << seats[i][j];
        std::cout << '\n' ;
    }
}

bool again()
{
    char ch ;
    std::cout << "reserve another seat? (Y/N) ";
    std::cin >> ch ;
    return ch == 'Y' || ch == 'y' ;
}

int main()
{
    char seats[NROWS][NCOLS];

    // 'initialise' to all free
    for( auto& row : seats ) for( char& c : row ) c = FREE ;

    do
    {
        display(seats) ;

        int x,y;
        std::cout << "\nWhich row would you want [1-" << NROWS << "]: ";
        std::cin >> x;
        std::cout << "Which column would you want[1-" << NCOLS << "]: ";
        std::cin >> y;

        reserve( seats, x-1, y-1 ); // -1 to adjust for zero-based indices of arrays
    }
    while( again() ) ;

    std::cout << "\nreservation status at the end:\n\n" ;
    display(seats) ;
}
Topic archived. No new replies allowed.