I need to validate a user input using getch() only to accept numeric input
`int input_put=getch();`
if(input >=0 && < 9){
}else{
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
getchreturns a character code. The character code for “0” is 48, not 0, although you can get away with using a character constant instead (since char constants are really integer constants) and that will be more readable. So:If you’re using Visual C++ (as your tags indicate), you may find the MSDN docs useful. For instance, you probably should be using
_getchinstead, or_getchwif you want to write software that can be used more globally. And in that same vein, you probably want to look atisdigit,isdigitw, and the like.