bool login_page()
{
int choice;
cout<<"Welcome to The First National Bank of Tamu"<<endl;
cout<<"Please make a selection"<<endl;
cout<<"1. Open a new account"<<endl;
cout<<"2. Login"<<endl;
cout<<"3. Close existing account"<<endl;
cout<<"4. Exit"<<endl;
cin>>choice;
if(choice!='1'||'2'||'3'||'4'){
error("You must select one of the option 1-4"<<endl;)
login_page();
}
bool again=true;
switch (choice){
case 1: new_acct(); login_page(); break;
case 2: login(); break;
case 3: close_acct();break;
case 4: cout<<"Thank You"<<endl; again=false; return again; break;
default: login_page(); return again;
}
}
but for some reason if i put a letter instead of an int, the program just goes haywire and just constantly loops. I thought the if statement would catch that? Any ideas?
Well, your problem is that you don't have a loop. Instead you have an inappropriate (though tempting) recursion which will cause endless trouble.
apart from that your if clause is wrong. It must be if(choice!='1'||choice!='2'||...)
further more if something wrong (like a letter) is entered cin sets an error (and doesn't recover from that!). All tries to read from cin will return immediately without setting the variable to any value. The recursion (if/default:) does the rest
Ya it was the cin that was giving me the biggest issue. I've fixed that now with a getline that will take in a string and from there check to make sure it is a number before executing