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