title: While loop with try catch fails at bad cin input
body: <p>I can't seem to figure out why this falls into a loop after getting non-int input. I've tried cin.flush(), which doesn't seem to exist, cin.clear(), which seems like it should work, even cin.sync() after reading someone else post about it working, but didn't seem to make much sense. Also tried cin.bad().</p>
  
  <p>Thank you very much for any help</p>
  
  <blockquote>
    <p>Please enter the first number: f
    Sorry, I don't think that's a number?</p>
    
    <p>Please enter the first number: Sorry,
    I don't think that's a number?</p>
    
    <p>Please enter the first number: Sorry,
    I don't think that's a number?</p>
    
    <p>Please enter the first number: Sorry,
    I don't think that's a number?</p>
    
    <p>Please enter the first number: Sorry,
    I don't think that's a number?Sorry,
    you d on't get any more tries. Press
    any key to continue . . .</p>
  </blockquote>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main(){
      int entry;
      int attempts = 1;
      int result;
      while(attempts &lt;= 5) {
          try {
              cout &lt;&lt; "\n\nPlease enter the first number: ";
              cin &gt;&gt; entry;
              if (cin.fail())
                  throw "Sorry, I don't think that's a number?";
              if (entry &lt; 0)
                  throw "Sorry, no negative numbers. Try something else? ";
              cout &lt;&lt; "\nNow the second number: ";
              cin &gt;&gt; entry;
              cin.clear();
              cin.get();
          }
          catch (char* error) {
              cout &lt;&lt; error;
              attempts++;
          }
      }
      if (attempts &gt; 5)
          cout &lt;&lt; "Sorry, you don\'t get any more tries.\n";
      system("pause");
      return 0;
  }
  </code></pre>