Input Questions

Reply

Join Date: Feb 2009
Posts: 4
Reputation: slik33 is an unknown quantity at this point 
Solved Threads: 0
slik33 slik33 is offline Offline
Newbie Poster

Input Questions

 
0
  #1
Mar 17th, 2009
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
  1. int menu( bool hidemenu,int *parr)
  2. {
  3. int choice;
  4. using namespace std;
  5. cout << "****MENU****" <<endl<<endl;
  6. cout << "(1) Set Array Size" << endl;
  7. if(parr != 0)
  8. cout << "(2) Set Array Values" << endl;
  9. if(hidemenu==false)
  10. {
  11. cout << "(3) Add Array Values" << endl;
  12. cout << "(4) Average Values in Array" << endl;
  13. cout << "(5) Find Highest Value in Array" << endl;
  14. cout << "(6) Find Lowest Value in Array" << endl;
  15. cout << "(7) Print the Array" << endl;
  16. cout << "(9) Delete the Array" << endl;
  17. cout << "(q) Quit" << endl;
  18. }
  19. cin >> choice;
  20. if(!cin)
  21. {clear,ignor,badInput=True,blah blah.....}
  22. //doesnt work b/c cant pass back badinput value
  23. return choice;

How could I get around this problem?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 838
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 130
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Input Questions

 
0
  #2
Mar 17th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 4
Reputation: slik33 is an unknown quantity at this point 
Solved Threads: 0
slik33 slik33 is offline Offline
Newbie Poster

Re: Input Questions

 
0
  #3
Mar 17th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 6
Reputation: Rashakil is an unknown quantity at this point 
Solved Threads: 0
Rashakil Rashakil is offline Offline
Banned

Re: Input Questions

 
0
  #4
Mar 17th, 2009
you are inputting to an int; there's your problem.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 110
Reputation: kenji is an unknown quantity at this point 
Solved Threads: 7
kenji's Avatar
kenji kenji is offline Offline
Junior Poster

Re: Input Questions

 
0
  #5
Mar 17th, 2009
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.
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC