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!!!
}
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');
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;
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");