The
cin.fail()
should only be true if the user tried to enter something
other than an integer.
Given the input "12abc" then you have a valid integer input: "12", leaving "abc" in the stream. (Whitespace is not significant.)
The way to check, then, is to peek() at the next character in the stream. If it is a period, then you have a real number. If it is not, then you have an integer.
So: (1) read an int (2) peek() to see what is next (3a) if it was a period read a float (or double) and add your int to it.
A more robust method is to read the entire line of user input, and validate its form yourself. Then you can read things like "42e7" and complain about things like "-3abc".
Here is a link about it. As noted in the link, you can ignore the fancy template stuff. The important thing is checking eof().
http://www.cplusplus.com/forum/beginner/13044/page1.html#msg62827
Remember, once you have the entire line of user's input, you can try to convert it to as many different things as you like. A simple method would be to simply >> int and >> float and check to see if their values match. If they do, look to see if the input contains a period or an 'E' or 'e' to decide between integer or real.
Hope this helps.