I have a problem where I need to display a seating assignment for an airplane. It will have 13 rows and 6 columns. If the seats are empty, it should display * and if the seat is taken it should show an X. There will eventually be 3 different types of seats to choose from, but I'm just trying to get the first part working. I can get the initial array to show all empty seats, but I'm having problems getting the seats reserved, then displaying the array correctly. Here is my code...

#include <iostream> 
#include <iomanip>  
using namespace std; 
 
int main()

{
	char tickets [13] [6];  //array of 13 rows and 6 columns
	char option;
	int x;
	int z;
	int row;
	char col;
	int numOfCol;
	int numOfRow;
	char a = 'A';
	int A;
	char b = 'B';
	int B;
	char c = 'C';
	int C;
	char d = 'D';
	int D;
	char e = 'E';
	int E;
	char f = 'F';
	int F;
	A = a - 65;  // |
	B = b - 65;  // | 
	C = c - 65;  // | This is supposed to change the column letter to a number in the array
	D = d - 65;  // |
	E = e -65;   // |
	F = f -65;    // |

	numOfCol = 6;
	numOfRow = 13;
	
	cout << setw(11) << "A" << setw(6) << "B" << setw(6) << "C" << setw(6) << "D"       << setw(6) << "E" << setw(6) << "F" << endl;

	for (x = 0; x < 13; x++)     // |
	for (z = 0; z < 6; z++)       // | This sets the array to all *
		tickets [x] [z] = '*';    // |
	
	for (x = 0; x < numOfRow; x++)             ///////////////////////|
	{						                              ////////|				
		cout << "Row" << setw(3) << x +1 << "";     /////////// |  This prints the array
		for (z = 0; z < numOfCol; z++)                    /////////// |
			cout << setw(5) << tickets [x] [z] << " ";      //// |
		cout << endl;					                   //// |
	}                                                                            //////////|

	cout << endl;

	cout << "Would you like a first class seat?  (Y/N)" << "";  
	 cin >> option;
		if (option == 'Y' || option == 'y')
		{
			cout << "Please enter the row number and seat letter you would like." << endl;
			cout << "Row" << "";
			cin >> row;
			cout << "Seat letter" << "";
			cin >> col;
			tickets [row][col] = 'X';  // Trying to assign X to the corresponding row and column

			cout << setw(5) << tickets [x] [z] << " ";  // Display the array again 
		}
		
		else if (option == 'N' || option == 'n')
		{
			cout << "Would you like an economy seat?  (Y/N)" << "";
			cin >> option;
			if (option == 'Y' || option == 'y')
			{
				cout << "Please enter the row number and seat letter you would like." << endl;
				cout << "Row" << "";
				cin >> row;
				cout << "Seat letter" << "";
				cin >> col;
				// assign seat
			}
			else cout << "Thank you for shopping." << endl;
			
		}
		
			
	 		
	return 0;
}

A few things. One, I think you would strongly benefit from using the toupper and tolower functions from the cctype library.

http://www.cplusplus.com/reference/clibrary/cctype/toupper.html
http://www.cplusplus.com/reference/clibrary/cctype/tolower.html

Also, I don't think you need to declare variables A through F.

In this code here:

if (option == 'Y' || option == 'y')
		{
			cout << "Please enter the row number and seat letter you would like." << endl;
			cout << "Row" << "";
			cin >> row;
			cout << "Seat letter" << "";
			cin >> col;
			tickets [row][col] = 'X';  // Trying to assign X to the corresponding row and column

			cout << setw(5) << tickets [x] [z] << " ";  // Display the array again 
		}

In the last line you are using x and z values that are not initialized to anything. You haven't defined them in a loop like you did before when you displayed the array. When you declare these variables at the top of main, you never initialize them so who knows what values are in them.

In this line:

tickets [row][col] = 'X';

keep in mind that col is a char, not an int, so it's going to be bigger than 5, which is as far as you have defined the array. This is where the "toupper" function could come in. You can change it to:

tickets[row][(int) toupper (col) - 65] = 'X';

That will give you a number in the second index from 0 to 5 if the user types in an 'A' through an 'F', whether lower or upper case, which is what you want.

You actually don't have to typecast the char to an int if you don't want, though I usually do. If you want to take it out, it would be this:

tickets[row][toupper (col) - 65] = 'X';

Thank you for the help, I'll play around with this some more and see what I can come up.

can u post that full codes?

commented: We sent em, didn't you get em? -1
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.