I started to work on this problem to provide the OP with some insight however I have come to conclusion that many others have within the comment section of the OPs original question: and that is that this question or problem has an indeterminate solution!
Reasoning:
If the user enters any of the following digits as a single entity for input { 0
, 1
, ... 9
} into the console this can be at the least interpreted as an int
or a char
type and at worst even a possible double
, but without the '.'
character being present we could eliminate that as a candidate. This problem definitely has ambiguity to it. Checking to see if it is a float or a double is easy; all one has to do is check the string to see if there is at least a '.'
then it's either a double
or a float
then check the last character of the string to see if it is a f
and if so then it is a float
. Checking to see if it is a character that is a non digit is easy, however distinguishing a single character digit between a char
and an int
is the troublesome part!
Work around:
You could conclude that if the input string is a single character and is a non digit then it is definitely a char
type.
You could conclude that if the input string is a single character and is a digit ASCII[48 - 57]
then you could conclude that it is an int
type. This would be considered a restraint.
You could conclude that if it isn't the above two it is at least a float
or a double
and it is a float
if and only if the last character of the string is a f
, but a .
must be present for it to be either of the two. Again these would be restraints that you would put on the accepted data input.