I want from program that it force the user to input valid value.When ever user enter caharcter in integer valriable it force the user to input the right value.But this does not work.If user input invalid value it start looping.
#include <iostream>
using namespace std;
int main()
{
int x;
re_enter_x:
cout<<"Enter X";
cin>>x;
if(cin.fail())
{
cout<<"INvalid Input ";
cin.clear();
cout<<x<<endl;
goto re_enter_x;
}
else
{
cout<<"Valid Number ";
}
return 0;
}