I'm having problems validating my input values.
To ensure only numeric input i did:
Code:
while(cin.good())
{
cout<<"Please enter a number: ";
cin>>i;
cout<<cout<<i;
}
However if i loop it and clear the buffer:
Code:
cout<<"Please enter your choice: ";
cin.seekg(0);
cin.clear();
cin>>i;
while(i<1 || i>9 || !cin.good())
{
cout<<"\aInput Error. Please make a valid choice: ";
cin.seekg(0);
cin.clear();
cin>>i;
}
In the first case if i enter any int it is expected and displayed as an int.
However in the second case
if i enter 08 instead of 8 or 09 instead of 9,
it only accepts the 0, in some cases it acceepts 010 as an octal value, and displays it at a later stage as 8.
Is there any other way i can clear the buffer.
Any help in resolving this problem will be appriciated.