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;
		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;
	{clear,ignor,badInput=True,blah blah.....}
//doesnt work b/c cant pass back badinput value
	return choice;

How could I get around this problem?

7 Years
Discussion Span
Last Post by kenji

I just assume that because when I type in q it doesnt let me input anything anymore it just keeps repeating my code without stopping.


The int choice is an int and as q is a char it sends the ascii value you should either make all your choices chars or make q a int like 0.

That may solve your problem.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.