title: c++ check if integer variable
body: <p>User enters date, currently validated to ensure the value is between 1 &amp; 31 inclusive.</p>
  
  <p>However, if they type a non integer value in, it just constantly repeats the error message in an infinite loop.</p>
  
  <p>I have looked around for the answer but everyone else who has asked appears to be far more advanced at c++ than I am, and therefore I don't even understand their initial code.</p>
  
  <p>Here's the code</p>
  
  <pre><code>void Menu::setDate()
  {
      date = 0;
  
      std::cout &lt;&lt; "Please enter todays date: (as an integer) ";
      do
      {
          std::cin &gt;&gt; date;   
          if (date &gt; 0 &amp;&amp; date &lt; 32)
          {
              break;
          }
          std::cout &lt;&lt; "Error: Please enter todays date: (as an integer) ";
      }
      while (true);
   }
  </code></pre>