Airplane Seating Program

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

struct airplaneseats
{

string column0;

string columnA;
string columnB;
string columnC;
string columnD;
string columnE;
string columnF;


};
void seatchart(airplaneseats, int classchoice)
{

airplaneseats row0 = {" ","A","B","C","D","E","F",};

airplaneseats row2 = {"1","-","-","*","-","*","*"};
airplaneseats row3 = {"2","-","*","-","*","-","*"};
airplaneseats row4 = {"3","-","-","*","*","-","*"};
airplaneseats row5 = {"4","*","-","*","-","*","*"};
airplaneseats row6 = {"5","-","*","-","*","-","-"};
airplaneseats row7 = {"6","-","*","-","-","-","*"};
airplaneseats row8 = {"7","*","-","-","-","*","*"};
airplaneseats row9 = {"8","-","*","-","*","*","-"};
airplaneseats row10 ={"9","*","-","*","*","-","*"};
airplaneseats row11 ={"10","-","*","-","*","*","*"};
airplaneseats row12 ={"11","-","-","*","-","*","-"};
airplaneseats row13 ={"12","-","-","*","*","-","-"};
airplaneseats row14 ={"13","-","-","-","-","*","-"};

if (classchoice == 1)
{
cout<<row0.column0<<"\t"

<<row0.columnA<<"\t"
<<row0.columnB<<"\t"
<<row0.columnC<<"\t"
<<row0.columnD<<"\t"
<<row0.columnE<<"\t"
<<row0.columnF<<endl<<endl

<<row2.column0<<"\t"

<<row2.columnA<<"\t"
<<row2.columnB<<"\t"
<<row2.columnC<<"\t"
<<row2.columnD<<"\t"
<<row2.columnE<<"\t"
<<row2.columnF<<endl<<endl
<<row3.column0<<"\t"

<<row3.columnA<<"\t"
<<row3.columnB<<"\t"
<<row3.columnC<<"\t"
<<row3.columnD<<"\t"
<<row3.columnE<<"\t"
<<row3.columnF<<endl<<endl;
}
else if (classchoice == 2)
{
cout<<row0.column0<<"\t"
<<row0.columnA<<"\t"
<<row0.columnB<<"\t"
<<row0.columnC<<"\t"
<<row0.columnD<<"\t"
<<row0.columnE<<"\t"
<<row0.columnF<<endl<<endl
<<row4.column0<<"\t"

<<row4.columnA<<"\t"
<<row4.columnB<<"\t"
<<row4.columnC<<"\t"
<<row4.columnD<<"\t"
<<row4.columnE<<"\t"
<<row4.columnF<<endl<<endl
<<row5.column0<<"\t"

<<row5.columnA<<"\t"
<<row5.columnB<<"\t"
<<row5.columnC<<"\t"
<<row5.columnD<<"\t"
<<row5.columnE<<"\t"
<<row5.columnF<<endl<<endl
<<row6.column0<<"\t"

<<row6.columnA<<"\t"
<<row6.columnB<<"\t"
<<row6.columnC<<"\t"
<<row6.columnD<<"\t"
<<row6.columnE<<"\t"
<<row6.columnF<<endl<<endl
<<row7.column0<<"\t"

<<row7.columnA<<"\t"
<<row7.columnB<<"\t"
<<row7.columnC<<"\t"
<<row7.columnD<<"\t"
<<row7.columnE<<"\t"
<<row7.columnF<<endl<<endl
<<row8.column0<<"\t"

<<row8.columnA<<"\t"
<<row8.columnB<<"\t"
<<row8.columnC<<"\t"
<<row8.columnD<<"\t"
<<row8.columnE<<"\t"
<<row8.columnF<<endl<<endl;
}
else if (classchoice == 3)
{
cout<<row0.column0<<"\t"

<<row0.columnA<<"\t"
<<row0.columnB<<"\t"
<<row0.columnC<<"\t"
<<row0.columnD<<"\t"
<<row0.columnE<<"\t"
<<row0.columnF<<endl<<endl
<<row9.column0<<"\t"

<<row9.columnA<<"\t"
<<row9.columnB<<"\t"
<<row9.columnC<<"\t"
<<row9.columnD<<"\t"
<<row9.columnE<<"\t"
<<row9.columnF<<endl<<endl
<<row10.column0<<"\t"

<<row10.columnA<<"\t"
<<row10.columnB<<"\t"
<<row10.columnC<<"\t"
<<row10.columnD<<"\t"
<<row10.columnE<<"\t"
<<row10.columnF<<endl<<endl
<<row11.column0<<"\t"

<<row11.columnA<<"\t"
<<row11.columnB<<"\t"
<<row11.columnC<<"\t"
<<row11.columnD<<"\t"
<<row11.columnE<<"\t"
<<row11.columnF<<endl<<endl
<<row12.column0<<"\t"

<<row12.columnA<<"\t"
<<row12.columnB<<"\t"
<<row12.columnC<<"\t"
<<row12.columnD<<"\t"
<<row12.columnE<<"\t"
<<row12.columnF<<endl<<endl
<<row13.column0<<"\t"

<<row13.columnA<<"\t"
<<row13.columnB<<"\t"
<<row13.columnC<<"\t"
<<row13.columnD<<"\t"
<<row13.columnE<<"\t"
<<row13.columnF<<endl<<endl
<<row14.column0<<"\t"

<<row14.columnA<<"\t"
<<row14.columnB<<"\t"
<<row14.columnC<<"\t"
<<row14.columnD<<"\t"
<<row14.columnE<<"\t"
<<row14.columnF<<endl<<endl;
}

}
int main()
{
int classchoice, desiredseatr;
string desiredseatc = "";
string reply = "";

cout<<"Which ticket type do you desire."<<endl<<"Our first two rows are first class, rows 3-7 are business class,"<<endl<<"and rows 8-13 are economy class. In which class would like to be seated?"<<endl<<"(Respond 1 for First Class, 2 for Business, and 3 for Economy).: ";
cin>>classchoice;
cout<<endl<<endl;
while ((classchoice == 0)||(classchoice >= 4))
{
cout<<"Error."<<" Please enter a class of 1, 2, or 3.: ";
cin>>classchoice;
cout<<endl;
}
seatchart(airplaneseats(), classchoice);
cout<<"Which seat would you like? "<<"\n"<<"Enter a row number: ";
cin>>desiredseatr;
while (classchoice == 1 && desiredseatr > 2)
{
cout<<"Error"<<"\n"<<"Please enter a row number less than 3: ";
cin>>desiredseatr;
}
while ((classchoice == 2 && desiredseatr < 3)||(classchoice == 2 && desiredseatr >7))
{
cout<<"Error"<<"\n"<<"Please enter a row number which is displayed: ";
cin>>desiredseatr;
}
while ((classchoice == 3 && desiredseatr < 8)||(classchoice == 2 && desiredseatr > 13))
{
cout<<"Error"<<"\n"<<"Please enter a row number which is displayed: ";
cin>>desiredseatr;
}
cout<<"Enter which letter you want your seat: ";
cin>>desiredseatc;


while ((desiredseatc == "G")||(desiredseatc == "g")||(desiredseatc == "H")||(desiredseatc == "h")||(desiredseatc == "I")||(desiredseatc == "i")||(desiredseatc == "J")||(desiredseatc == "j")||(desiredseatc == "K")||(desiredseatc == "k")||(desiredseatc == "L")||(desiredseatc == "l")||(desiredseatc == "M")||(desiredseatc == "m")||(desiredseatc == "N")||(desiredseatc == "n")||(desiredseatc == "O")||(desiredseatc == "o")||(desiredseatc == "P")||(desiredseatc == "p")||(desiredseatc == "Q")||(desiredseatc == "q")||(desiredseatc == "R")||(desiredseatc == "r")||(desiredseatc == "S")||(desiredseatc == "s")||(desiredseatc == "T")||(desiredseatc == "t")||(desiredseatc == "U")||(desiredseatc == "u")||(desiredseatc == "V")||(desiredseatc == "v")||(desiredseatc == "W")||(desiredseatc == "w")||(desiredseatc == "X")||(desiredseatc == "x")||(desiredseatc == "Y")||(desiredseatc == "y")||(desiredseatc == "Z")||(desiredseatc == "z"))
{
cout<<"Error"<<endl<<"Enter a letter that is displayed: ";
cin>>desiredseatc;

}

cout<<endl;
cout<<"Congratulations! Your ticket has been booked.";
cout<<endl<<endl;
cout<<"Would you like to book another seat ticket?(Y or N): ";
cin>>reply;
cout<<endl;
while((reply == "Y")||(reply == "y"))
{
cout<<"Which ticket type do you desire."<<endl<<"Our first two rows are first class, rows 3-7 are business class,"<<endl<<"and rows 8-13 are economy class. In which class would like to be seated?"<<endl<<"(Respond 1 for First Class, 2 for Business, and 3 for Economy).: ";
cin>>classchoice;
cout<<endl<<endl;

seatchart(airplaneseats(), classchoice);
cout<<"Which seat would you like? "<<"\n"<<"Enter a row: ";
cin>>desiredseatr;
while (classchoice == 1 && desiredseatr > 2)
{
cout<<"Error"<<"\n"<<"Please enter a row number less than 3: ";
cin>>desiredseatr;
}
while ((classchoice == 2 && desiredseatr < 3)||(classchoice == 2 && desiredseatr >7))
{
cout<<"Error"<<"\n"<<"Please enter a row number which is displayed: ";
cin>>desiredseatr;
}
while ((classchoice == 3 && desiredseatr < 8)||(classchoice == 2 && desiredseatr > 13))
{
cout<<"Error"<<"\n"<<"Please enter a row number which is displayed: ";
cin>>desiredseatr;
}
cout<<"Enter which letter you want your seat: ";
cin>>desiredseatc;
while ((desiredseatc == "G")||(desiredseatc == "g")||(desiredseatc == "H")||(desiredseatc == "h")||(desiredseatc == "I")||(desiredseatc == "i")||(desiredseatc == "J")||(desiredseatc == "j")||(desiredseatc == "K")||(desiredseatc == "k")||(desiredseatc == "L")||(desiredseatc == "l")||(desiredseatc == "M")||(desiredseatc == "m")||(desiredseatc == "N")||(desiredseatc == "n")||(desiredseatc == "O")||(desiredseatc == "o")||(desiredseatc == "P")||(desiredseatc == "p")||(desiredseatc == "Q")||(desiredseatc == "q")||(desiredseatc == "R")||(desiredseatc == "r")||(desiredseatc == "S")||(desiredseatc == "s")||(desiredseatc == "T")||(desiredseatc == "t")||(desiredseatc == "U")||(desiredseatc == "u")||(desiredseatc == "V")||(desiredseatc == "v")||(desiredseatc == "W")||(desiredseatc == "w")||(desiredseatc == "X")||(desiredseatc == "x")||(desiredseatc == "Y")||(desiredseatc == "y")||(desiredseatc == "Z")||(desiredseatc == "z"))
{
cout<<"Error"<<endl<<"Enter a letter that is displayed: ";
cin>>desiredseatc;
}

cout<<endl;
cout<<"Congratulations! Your ticket has been booked.";
cout<<endl<<endl;
cout<<"Would you like to book another seat ticket?(Y or N): ";
cin>>reply;

}

cout<<"Alright everything is set we hope you enjoy your flight.";

cout<<endl<<endl;
system("pause");
}
This is a program that is supposed to prompt the user to input the class in which he would like to be seated, and when the user inputs the class the program should show a seating chart of the class. So far I have the seating chart, and display right, but I still have some problems.

My program has the following bugs:
1. If the user inputs anything other than a number when prompted to enter the class in which they would like to be seated, the program terminates as if it had completed successfully.
2. If the user inputs anything other than a number when prompted to input a row number the program completes as if it completed successfully.
3. If the user inputs a number when prompted to enter the column letter he wants, the program goes on to the next step as if the prompt had been answered correctly.
For 1. and 2.:
When the wrong input is given, cin sets its failbit flag to true, and while cin.fail()1 would return true, the object will not attempt to read any more information. You can fix this by clearing the flags, e.g.
1
2
3
4
5
6
7
int choice(0);
cout << "Please enter your choice: ";
cin >> choice;
while(cin.fail()){
    cout << "Error, not an integer. Please enter your choice again: ";
    cin >> choice;
}


For 3:
Even if you enter a number, the program will not know that. Instead, it treats your input as if it were a C-string, so for example if you entered 92, the program would interpret it as "92". Considering all you want is a single letter, you can probably just do this:
1
2
3
4
5
6
char desiredcolumn('\0');
cin >> desiredcolumn;
toupper(desiredcolumn); //Forget checking for both upper- and lowercase. Just use one case.
while(desiredcolumn < 'G' || desiredcolumn > 'Z'){ //Remember chars can be treated as ints
//Blah blah blah...
}




1 See http://www.cplusplus.com/reference/ios/ios/fail/.
Hey Daleth thanks man I really appreciate it. I've been working on this mug for a long time.
Topic archived. No new replies allowed.