Here is the code
double enter_number()
{
double number;
while(1)
{
cin>>number;
if(cin.fail())
{
cin.clear()
#include
#include
#include
using namespace std;
int get_int(void);
int main()
{
puts("Enter a number");
cout<<"The integer is "<
This works fine for any integer. It can even check if you enter a space or any other character after the integer. The only problem is that it does not make use of std::cin. But, the problem with std::cin is that it ignores any space character after the integer and happily takes the integer as input.