| | |
Input Questions
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 4
Reputation:
Solved Threads: 0
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
How could I get around this problem?
C++ Syntax (Toggle Plain Text)
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?
What is the error that you are getting? Or whats going wrong, how do you know it fails?
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
The
That may solve your problem.
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.
And she said "Let there be light" and on the seveth day Windows booted.
And the crowds screamed in terror and cowered in fear for Microsoft had approached.
From the testament of 10011101
And the crowds screamed in terror and cowered in fear for Microsoft had approached.
From the testament of 10011101
![]() |
Other Threads in the C++ Forum
- Previous Thread: Child removal problem with Xerces
- Next Thread: Help auto adjust command
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





