I am working inside a function and am already passing back a value. Inside the function I am using cin to get an int from the user. If they want to quit they type q. The input buffer fails when this happens. I could use an if statement and then clear the buffer but I cant pass back another value. For example
int menu( bool hidemenu,int *parr)
{
int choice;
using namespace std;
cout << "****MENU****" <<endl<<endl;
cout << "(1) Set Array Size" << endl;
if(parr != 0)
cout << "(2) Set Array Values" << endl;
if(hidemenu==false)
{
cout << "(3) Add Array Values" << endl;
cout << "(4) Average Values in Array" << endl;
cout << "(5) Find Highest Value in Array" << endl;
cout << "(6) Find Lowest Value in Array" << endl;
cout << "(7) Print the Array" << endl;
cout << "(9) Delete the Array" << endl;
cout << "(q) Quit" << endl;
}
cin >> choice;
if(!cin)
{clear,ignor,badInput=True,blah blah.....}
//doesnt work b/c cant pass back badinput value
return choice;
How could I get around this problem?