| bennyboy (15) | |||
|
Hello I am trying to test if the cin input matches my criteria. I want the program to check if the input is an integer AND if it's within range (1-4). It is for a basic menu system for a minesweeper game... Here's what I have:
When debugging the program, the program loops around the first IF statement over and over. Do I need to clear the int 'select' before going back to start? | |||
|
Last edited on
|
|||
| Chervil (1205) | |||
You need to clear the error condition for non-integer input. Also clear the invalid characters from the input buffer.
The use of system("pause") should not be necessary, the program will pause as it awaits user input in any case. | |||
|
Last edited on
|
|||
| bennyboy (15) | |||
|
Thank you! Now, I need to use this function multiple times in my code. How would I include this in a header file I already have that contains other useful functions that I have been calling to in my code? Just putting this doesn't work when compiling:
I get "cin - undeclared identifier" error when compiling main.cpp What to I need to do to it to get it to work? Thanks. | |||
|
Last edited on
|
|||
| ResidentBiscuit (2645) | |
| Well you need to either specify somewhere in the scope of cin that you're using std namespace, or attach std:: in front of cin. | |
|
|
|
| bennyboy (15) | ||
Bingo! Thank you both for your help, much appreciated. | ||
|
|
||