I have to make a program that reads the number of seats and stores it in a two dimensional array. The empty seats is hashtag and if the user buys a seat it becomes . The odd rows have 15 seats and even have 20.
When I purchase a seat, it puts the
on the seat but when I buy another seat it removes it and puts on the newly purchased seat. How can I make it so it saves the that it prints on every seat.

#include <iostream>

using namespace std;
int column2, row2,total = 0;
    char ab[20][15];
    char EMPTY = '#';
    char FULL = '*';
    int seat = 300;
    int seat2 = 0;
    int Quit = 1;
    int choice;
    int cost,answer,price;

void ShowSeats()
{    
    cout << "\tSeats" << endl;
    cout << "       0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19\n";

    for (int i = 0; i < 15; i++) {
        for (int j = 0; j < 20; j++) {
            ab[i][j] = EMPTY;
            if (i % 2 && j == 14) // 0 is false, 1 is true
            {
                break;
            }
            if (i == row2 && j == column2) // assuming these numbers start from 0
            {
                ab[i][j] = '*';
            }
        }
    }
    for (int i = 0; i < 15; i++) {
        cout << endl
             << "Row " << (i + 1);
        for (int j = 0; j < 20; j++) {

            cout << "  " << ab[i][j];

        }
    }
}

int main()
{

while (true){    
    cout << "Please select the row you would like to sit in: ";
    cin >> row2;
    cout << "Please select the seat you would like to sit in: ";
    cin >> column2;
    cout<< "Enter the price";
    cin >> price;
    if (ab [row2] [column2] == '*')
        {
            cout << "Sorry that seat is sold-out, Please select a new seat.";
            cout << endl;
        }
        else
        {
            cost = price;

            cout << "That ticket costs: " << cost << endl;
            cout << "Confirm Purchase? Enter (1 = YES)";
            cin >> answer;
            seat = seat - answer;
            seat2 += answer;

            if (answer == 1)
            {
                cout << "Your ticket purchase has been confirmed." << endl;
                ab [row2][column2] = FULL;
                total = total + cost;
                cout << "Would you like to look at another seat? (1 = YES)";
                cin>>Quit;
            }
    ShowSeats();
    }

}}

It shows me this when I purchase row 2 and seat 2
https://gyazo.com/0d8bd7ed02e969110db47b428c512f24

But when I purchase row 2 seat 3 it does not save the previous purchase and I want it to save both.
https://gyazo.com/f865ba7145d1fafac246836975f2ee00

Think real hard about lines 34 and 71.

In line 34 you print from a certain row, then line 71 puts it into a different row. Think real hard where line 71 stored the FULL value.
numbertwo.PNG

First off I would suggest creating an initialize function that sets all array elements to EMPTY and runs only once at the beginning of execution. Separating your program logic into methods or blocks will improve readability for yourself and others.

Second, as it stands now, you need to change your for() loop control statements to:
int i = 1; i <= 15;
and
int j = 1; j <= 20;
because both indexes are starting at zero, which makes the statement ( i%2 && j ==14) useless. You can use (i%2) to determine if you're referencing an even or odd row and based on that you set j to 15 or 20.

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.