I'm working on a seat diagram program, and it's not reading the input how it should. Also when the user enters a seat it should change the letter to an X. The program isn't reading the input correctly. When I tell the program to print the seat the user picked, it doesn't show anything at all. I posted another topic similar to this where I had a Seat class, but I was doing the assignment wrong.

#include<iostream>
#include<iomanip>
#include<string>

using namespace std;



string seat;
char seatLetter;
int seatRow;

void main(){

string A1="A",A2="A",A3="A",A4="A",A5="A",A6="A",A7="A";
string B1="B",B2="B",B3="B",B4="B",B5="B",B6="B",B7="B";
string C1="C",C2="C",C3="C",C4="C",C5="C",C6="C",C7="C";
string D1="D",D2="D",D3="D",D4="D",D5="D",D6="D",D7="D";

	cout<<"Seat diagram" <<endl;
	cout<<"1 \t" <<A1 <<"\t" <<B1 <<"\t" <<C1  <<"\t" <<D1<<endl;
	cout<<"2 \t" <<A2 <<"\t" <<B2 <<"\t" <<C2  <<"\t" <<D2<<endl; 
	cout<<"3 \t" <<A3 <<"\t" <<B3 <<"\t" <<C3  <<"\t" <<D3<<endl; 
	cout<<"4 \t" <<A4 <<"\t" <<B4 <<"\t" <<C4  <<"\t" <<D4<<endl; 
	cout<<"5 \t" <<A5 <<"\t" <<B5 <<"\t" <<C5  <<"\t" <<D5<<endl; 
	cout<<"6 \t" <<A6 <<"\t" <<B6 <<"\t" <<C6  <<"\t" <<D6<<endl; 
	cout<<"7 \t" <<A7 <<"\t" <<B7 <<"\t" <<C7  <<"\t" <<D7<<endl; 

	while(seatRow!=8){
		cout<<"Enter the row of the seat you would like: "; cin>>seatRow;
		cout<<"Enter the letter of the seat you would like: "; cin>>seatLetter;
		seat = seatLetter+""+seatRow;
		cout<<seat  <<endl;

	cout<<"Seat diagram" <<endl;
	cout<<"1 \t" <<A1 <<"\t" <<B1 <<"\t" <<C1  <<"\t" <<D1<<endl;
	cout<<"2 \t" <<A2 <<"\t" <<B2 <<"\t" <<C2  <<"\t" <<D2<<endl; 
	cout<<"3 \t" <<A3 <<"\t" <<B3 <<"\t" <<C3  <<"\t" <<D3<<endl; 
	cout<<"4 \t" <<A4 <<"\t" <<B4 <<"\t" <<C4  <<"\t" <<D4<<endl; 
	cout<<"5 \t" <<A5 <<"\t" <<B5 <<"\t" <<C5  <<"\t" <<D5<<endl; 
	cout<<"6 \t" <<A6 <<"\t" <<B6 <<"\t" <<C6  <<"\t" <<D6<<endl; 
	cout<<"7 \t" <<A7 <<"\t" <<B7 <<"\t" <<C7  <<"\t" <<D7<<endl; 
	}

}

On lines 10 and 11, you create two variables; an int and a char. You then, on line 32, concatenate them with a std::string. This is where the problem is.

If you made those two variables std::string as well, you'd get the seat output on line 33.

Alternatively, leave them as an int and a char and enhance your concatenation on line 32.

Changing the variables to strings resolved the issue. Now I need the program to change a seat to X when the user chooses it. For example A user chooses A1. I need the value of the A1 string changed to "X" instead of "A"

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.