#include <iostream>
#include <string>
#include <sstream>

double ask_for_number(std::string const &prompt)
{
    double x;
    std::string line;
    while((std::cout << prompt << ": ") //prompt for input
       && std::getline(std::cin, line) //read whole line (almost never fails)
       && !(std::istringstream{line} >> x)) //validate input
    {
        std::cout << "Invalid input, please try again." << std::endl;
    }
    return x;
}

int main()
{
	int n1 = ask_for_number("Enter a number");
	int n2 = ask_for_number("Enter another number");

	std::cout << "n1 + n1 = " << n1 + n2 << std::endl;
}
