To be resilient against non-number inputs is a bit tricky, you'd need to first read in a string, then try to convert it to a double with std::stod while catching exceptions that std::stod may throw. It won't throw an exception if it looks like an int, in that case it will just store the integer value in the double.
Forum