So I'm making an airplane seating program and I want my user to enter a number to choose a row and enter a letter for to choose one of the six choices in a row (A to F). I also want the user to keep entering seats as long as they input the letter "C". I have most of the code written but I can't make it output for some reason the seats are not outputting after initializing and displaying them for the first time. The program just stops. I'm trying to output the result before correcting any mistakes I've made in the logic.
//Any unused includes are part of the default code
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cassert>
using namespace std;
const int rowsz = 5;
const int colsz = 6;
int main()
{
char seating[rowsz][colsz];
char y = ' '; //Row
char x = ' '; //Col
char taken = 'X'; // This letter is for marking booked seats
char letter = ' '; // This letter initializes the seat positions.
char let = ' '; // Choice for a seat
char choice = 'c'; // This let's the user quit or continue booking seats
int rownum = 1; // Row number
for(int row = 1; row <= rowsz; row++)
{
letter = 'A';
cout << rownum;
rownum++;
for(int col = 0; col < colsz; col++)
{
seating[row][col] = letter;
letter++;
cout << seating[row][col];
}
cout << endl;
}
cout << "Would you like to get a seat? Press C. TO quit, press Q: "; cin >> choice;
while(toupper(choice) == 'C')
{
cout << "Enter a row. Ex: 1,2,3... ";cin >> y;
cout << "Enter a Letter for a seat: "; cin >> x;
if(toupper(x) == 'A')
x = 0;
if(toupper(x) == 'B')
x = 1;
if(toupper(x) == 'C')
x = 2;
if(toupper(x) == 'D')
x = 3;
if(toupper(x) == 'E')
x = 4;
if(toupper(x) == 'F')
x = 5;
seating[y][x] = taken;
for(int row = 1; row <= rowsz; row++)
{
for(int col = 0; col < colsz; col++)
{
cout << seating[row][col];
}
cout << endl;
}
cout << "Seat again? Press C to continue to seat and press Q to quit. "; cin >> choice;
}
if(toupper(choice) != 'C')
{
cout << "Thank you for using this program! " << endl;
}
return 0;
}
If anyone is still reading this old post, I managed to get it working a long time ago:
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cassert>
using namespace std;
//const int 5 = 5;
//rconst int 6 = 6;
int main()
{
char seating[5][6];
int y = 0; //Row
int x = 0; //Col
char letter = ' '; // This letter initializes the seat positions.
char let = ' '; // Choice for a seat
char choice = 'c'; // This let's the user quit or continue booking seats
int rownum = 1; // Row number
for(int row = 0; row < 5; row++)
{
letter = 'A';
cout << rownum;
rownum++;
for(int col = 0; col < 6; col++)
{
seating[row][col] = letter;
letter++;
cout << seating[row][col];
}
cout << endl;
}
cout << "Would you like to get a seat? Press C. TO quit, press Q: "; cin >> choice;
while(toupper(choice) == 'C')
{
cout << "Enter a row. Ex: 1,2,3... ";cin >> x;
if(x <= 0 || x > 5){
cout << "Try again: "; cin >> x;
}
cout << "Enter a Letter for a seat: "; cin >> let;
if(toupper(let) == 'A'){
y = 0;
}
else if(toupper(let) == 'B'){
y = 1;
}
else if(toupper(let) == 'C'){
y = 2;
}
else if(toupper(let) == 'D'){
y = 3;
}
else if(toupper(let) == 'E'){
y = 4;
}
else if(toupper(let) == 'F'){
y = 5;
}
else{
cout << "Wrong Input: " << endl;
cin >> let;
}
while(seating[x][y] == 'X')
{
cout << "Try again? Row:" << endl;
cin >> x;
cout <<" and letter: " << endl;
cin >> let;
}
seating[x - 1][y] = 'X';
rownum = 1;
for(int row = 0; row < 5; row++)
{
cout << rownum;
rownum++;
for(int col = 0; col < 6; col++)
{
cout << seating[row][col];
}
cout << endl;
}
cout << "Seat again? Press C to continue to seat and press Q to quit. "; cin >> choice;
}
if(toupper(choice) != 'C')
{
cout << "Thank you for using this program! " << endl;
}
return 0;
}