title: C++ validation using dowhile
body: <p>This is my code, but if the user enters one of the values being checked for, it picks up the error, but displays the error message in a infinite loop</p>
  
  <pre><code>std::cin &gt;&gt; withdrawAmount;
      do
      {
          if (withdrawAmount &lt; balance &amp;&amp; withdrawAmount &gt; 0)
          {
          break;
          }
      std::cout &lt;&lt; "Error: You have insufficient balance to withdraw " &lt;&lt; withdrawAmount &lt;&lt; " pounds. Your balance is only " &lt;&lt; balance &lt;&lt; " pounds." &lt;&lt; std::endl;
      std::cout &lt;&lt; "Or you have entered a non positive integer" &lt;&lt; std::endl;
      }
      while (true);
  
  // some more code
  </code></pre>
  
  <p>whereas this code, which to works correctly, looks the same to me</p>
  
  <pre><code>std::cout &lt;&lt; "Please enter todays date: (as an integer) ";
      do
      {
      std::cin &gt;&gt; date;   
          if (date &gt; 1 &amp;&amp; date &lt; 31)
          {
          break;
          }
      std::cout &lt;&lt; "Error: Please enter todays date: (as an integer) ";
      }
      while (true);
  
  // some more code
  </code></pre>
  
  <p>Also if someone could show me how to add validation to check what they have entered is in fact an integer (not 'two' for example that would be awesome)</p>