Monday, 27 May 2013

How to check if a variable is an integer?

How to check if a variable is an integer?

I'm going through my C++ book and have currently made a working Guess The Number game.
The game generates a random number based on current time, has the user input their guess, and then tells them whether it was too high, too low, or the correct number.
The game functions fine if you enter a number, but returns 'Too High' if you enter something that is not a number (such as a letter or punctuation). Not only does it return 'too high', but it also continually returns it.
I was wondering what I could do to check if the guess, as input by the user, is an integer and if it is not, to return 'Not a number. Guess again.'
Here is the code; http://pastebin.com/9ALE2A4Z

No comments:

Post a Comment