View Single Post
Join Date: Jan 2008
Posts: 3,757
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 491
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

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

 
0
  #2
Nov 18th, 2008
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.
Reply With Quote