C++ - Check cin for mistakes
<p>I have a while loop that restarts if the users inputs something wrong.</p>

<pre><code>do{
    cerr&lt;&lt;"Input the numbers divided by a space"&lt;&lt;endl;
    cin&gt;&gt;number1&gt;&gt;number2;
    hiba=(cin.fail() || number1&lt;1 || number1&gt;100 || number2&lt;1 || number2&gt;100);
    if(fail){
        getline(cin, sz);
        cerr&lt;&lt;"Wrong input"&lt;&lt;endl;
    }
}while(fail);
</code></pre>

<p>Both variables are integers and it works if the numbers are either below 0 or above 100, but it doesn't work if the user inputs a character, because it starts an infinite loop.</p>