![]() |
|
#1
|
|||
|
|||
Help with integer inputsThis may have an easy solution, but I cant figure out how to do this. I am looking for the user to input an integer. The variable is defined as an integer, but when the user enters a character it still works through the code. Is there a way to verify if the user has entered an integer? I would like to possibly display an error message if they enter a character so I would like a way to recognized a character input and for it to react as i wish. Im working with c++ and the cin command for the input. Thanks for your help
|
|
#2
|
|||
|
|||
|
You can use the functions located in ctype.h:
CPP / C++ / C Code:
Or create your own: CPP / C++ / C Code:
If the integer'll be more than 1 character long I think you'll just have to loop through the string and test each character. |
Recent GIDBlog
Flickr uploads of IA pictures by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| base conversions c++ (please help) | greensand | C++ Forum | 10 | 06-Mar-2005 08:11 |
| How to create integer variables | OETN | FLTK Forum | 4 | 26-Dec-2004 10:04 |
| Best way to use integer constants | crystalattice | C Programming Language | 5 | 29-Aug-2004 17:48 |
| converting binary to integer... | tru504187211 | C++ Forum | 3 | 10-Feb-2004 07:11 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The