Monday, May 24, 2010

I have to input integer for c++ code how can i check whether the user input integer or a string character?

then if he input a charecter how to promt him to enter integer again

I have to input integer for c++ code how can i check whether the user input integer or a string character?
there are functions available in ctype.h header


isalph()


isalnum()


isdigit()


use them
Reply:all input is char values, they must be converted to int values, I believe 0 the character 0 is equal to 32, but you can say





if(x%26gt;='0' || x%26lt;'9') then


{


cout%26lt;%26lt;"This character is a number"


}





if you then wanted to convert it to a real number just subtract the character 0 from it IE '9' - '0' = 9

florist shop

No comments:

Post a Comment