I wrote a program that allow users input a double value, if I input a string or a char value, it turns out to be a logical error. I've tried this:
bool h;
float value;
do{
cout<<"enter a value"<<endl;
cin>>value;
if(cin.fail()){
cout<<"error, enter a value!"<<endl;
cin.clear();
cin.ignore();
h=true;}
else
h=false;
}
while(h==true);
If I input "mee" for instance it gives me "error, enter a value!" thrice instead of once. I thought cin.ignore(), cin.clear() is used to erase the input stream. Thanks in advance!