Infinite Loop when checking conditions c++ !cin
<p>I'm basically expecting a number as input. The magnitude is negligible now as I know my else if loop works fine. But testing if its a number proves to be a bit trickier. I just want to call the function again and start over if the user enters in something alphanumeric or just plain words. Or pressed enter. Something that is not a number. I tried !cin since I am inputting into "int numTemp", but that just results in an infinite loop that spills out "what is the bitrate" countless times. Anyone know what I'm doing wrong? I tried putting cin.clear() and cin.ignore(100, "\n") inside the first if statement but to no avail. Thanks in advance. </p>

<pre><code>bool iTunes::setBitRate()
{
cout &lt;&lt; "What is the bitrate? ";
int numTemp;
cin &gt;&gt; numTemp;
if (!cin)
{
    cout &lt;&lt; "WRONG" &lt;&lt; endl;
    setBitRate();
}
else if( numTemp &lt; MIN_BITRATE || numTemp &gt; MAX_BITRATE)
{
    cout &lt;&lt; "Bit Rate out of range" &lt;&lt; endl;
    setBitRate();
}
else
{
    bitRate = numTemp;
}
}
</code></pre>
