Why do you pass a float to isalpha
? What's the point storing a character in a float and checking it?
The declaration for isalpha
is int isalpha ( int c );
, so if you pass a float to it, the float will be truncated to int
, making it produce a wrong result. Try inputting 99.5 or something like that and see
More importantly, isalpha
only works with a char value or EOF, other values will invoke undefined behavior
The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
http://en.cppreference.com/w/cpp/string/byte/isalpha
This is essentially an XY problem. isalpha
is not a way to validate input values. You need to get the input as string and check whether it fits your condition or not