I've been trying to finish this airplane seating program I've been working on for a month or two. The problem I have right now is that 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.

So I originally used string but I heard from Daleth that Char was better, but I don't know how to apply it. I figured out cin.fail, but I've yet to finish this part. Please Help!!!

So I originally used string but I heard from Daleth that Char was better, but I don't know how to apply it. I figured out cin.fail, but I've yet to finish this part. Please Help!!!

#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;

bool bfail;

string desiredseatc = "";

string reply = "";

do

{

cout<<"In which would you like to be seated?"<<endl<<"Please enter 1 for First Class, 2 for Business Class, and 3 for Economy: ";

cin>>classchoice;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

while (classchoice == 0||classchoice >= 4)

{

cout<<"Please enter 1 for First Class, 2 for Business Class, and 3 for Economy: ";

cin>>classchoice;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

}

}while (bfail == true);

cout<<endl<<endl;

seatchart(airplaneseats(), classchoice);

do

{

cout<<"In which row number would you like to be seated?(Enter row number): ";

cin>>desiredseatr;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

}while(bfail == true);

while (classchoice == 1 && desiredseatr > 2)

{

cout<<"\n"<<"Enter a row number that is displayed: ";

cin>>desiredseatr;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

}

while ((classchoice == 2 && desiredseatr < 3)||(classchoice == 2 && desiredseatr >7))

{

cout<<"\n"<<"Enter a row number that is displayed: ";

cin>>desiredseatr;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

}

while ((classchoice == 3 && desiredseatr < 8)||(classchoice == 2 && desiredseatr > 13))

{

cout<<"\n"<<"Enter a row number that is displayed: ";

cin>>desiredseatr;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

}

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;

system("pause");

}

#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;

bool bfail;

string desiredseatc = "";

string reply = "";

do

{

cout<<"In which would you like to be seated?"<<endl<<"Please enter 1 for First Class, 2 for Business Class, and 3 for Economy: ";

cin>>classchoice;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

while (classchoice == 0||classchoice >= 4)

{

cout<<"Please enter 1 for First Class, 2 for Business Class, and 3 for Economy: ";

cin>>classchoice;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

}

}while (bfail == true);

cout<<endl<<endl;

seatchart(airplaneseats(), classchoice);

do

{

cout<<"In which row number would you like to be seated?(Enter row number): ";

cin>>desiredseatr;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

}while(bfail == true);

while (classchoice == 1 && desiredseatr > 2)

{

cout<<"\n"<<"Enter a row number that is displayed: ";

cin>>desiredseatr;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

}

while ((classchoice == 2 && desiredseatr < 3)||(classchoice == 2 && desiredseatr >7))

{

cout<<"\n"<<"Enter a row number that is displayed: ";

cin>>desiredseatr;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

}

while ((classchoice == 3 && desiredseatr < 8)||(classchoice == 2 && desiredseatr > 13))

{

cout<<"\n"<<"Enter a row number that is displayed: ";

cin>>desiredseatr;

bfail = cin.fail();

cin.clear();

cin.ignore(numeric_limits<streamsize>::max(),'\n');

}

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;

system("pause");

}

Topic archived. No new replies allowed.