problem with an exercise.

Using only cin, cout and their related commands, write code to receive
input from the user and print either real or integer, depending on whether the
user entered a real number (e.g., 14.7) or an integer (e.g., 14).you can assume that the input is either a real number or an integer. You are not to use the peek function.

i tired cin.fail(), buts its no use since it won't give me a flag when i tried to read as an integer.

any hints?
maybe make the program check if it's evenly divisible by one? not sure how though, im fairly new at this
well i tried by few methods but none did not work;

how would dividing by one help?
You could try using the isdigit functions. See here: http://www.cplusplus.com/reference/std/locale/isdigit/
it wouldn't help sorry, i was thinking of something else
Just read a double and define that it's an integer if it's close to the next integer.
You can use fmod to get the remainder of a floating point division:
http://www.cplusplus.com/reference/clibrary/cmath/fmod/
Topic archived. No new replies allowed.