Skip to main content
gamedev.net
🔒 Locked

i

Started by aeleneski Feb 4, 2004 at 4:16 PM 2 replies 250+ views
Original Post
aeleneski
aeleneski
i [Edited by - aeleneski on April 24, 2006 11:14:57 PM]
SiCrane
SiCrane
What method are you using to get input? And what programming language?
SiCrane
SiCrane
After you use operator >>() on cin, check the fail bit (cin.fail()). If the fail bit is set then the extraction operation couldn''t be performed, and probably because the input wasn''t actually an integer.

I''m guessing what''s happening in your code is that when you perform extraction on the stream, it fails the operation and sets the variable you used to a negative number. When you enter your loop it continues to fail and thus you go into an infinite loop.
Oluseyi
Oluseyi
quote:
Original post by aeleneski
but if at any time I put in something other than a negative or positive number the program would freeze.
That would be the infinite loop he talked about.

Read your input into a string and use a stringstream to extract the number. If it fails then you can admonish the user to enter a number without hanging.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.