View Single Post
Join Date: Nov 2008
Posts: 43
Reputation: davids2004 is an unknown quantity at this point 
Solved Threads: 0
davids2004 davids2004 is offline Offline
Light Poster

Re: Need help not allowing a negative number to be input

 
0
  #3
Nov 18th, 2008
Originally Posted by VernonDozier View Post
Write a function that does not allow for negative input:

  1. int GetNonNegativeInteger ()
  2. {
  3. int input;
  4. cin >> input;
  5. while (input < 0)
  6. {
  7. // display error message.
  8. // ask for input again
  9. }
  10.  
  11. return input;
  12. }



Call this function from main when you need non-negative integer input.
Now I am confused.
Last edited by davids2004; Nov 18th, 2008 at 12:28 am.
Reply With Quote