title: C++ - cin to only take one integer
body: <p>This code works fine if I enter something that isn't a number in, e.g. <code>F</code>: it will print the error message. However, if I enter e.g. <code>2F2</code> or , it will take the <code>2</code> and pass the check, continue in my code and on the next <code>cin &gt;&gt;</code> statement it will put the <code>F</code> in, and then it loops back and puts the <code>2</code> in.</p>
  
  <p>How do I make it so it only accepts a single number e.g. <code>2</code> and not e.g. <code>2F2</code> or <code>2.2</code>?</p>
  
  <pre><code>int bet = 0;
  // User input for bet 
  cout &lt;&lt; " Place your bet: ";
  cin &gt;&gt; bet;
  cout &lt;&lt;
  // Check if the bet is a number
  if (!cin.good())
  {
      cin.clear();
      cin.ignore();
      cout &lt;&lt; endl &lt;&lt; "Please enter a valid number" &lt;&lt; endl;
      return;
  }
  </code></pre>