title: How to have a good validation to check input is numeric
body: <p>I have seen several posts in SO asking for validation to check whether input is numeric. However there seems to have flaws in their proposed solutions.</p>
  
  <p>Consider the following example for input of numbers:</p>
  
  <pre><code>for (int x=0; x&lt;10; x++)
  {
      cout &lt;&lt; x+1 &lt;&lt;  ") Input a number: ";
      cin &gt;&gt; num;
      while (cin.fail())
      {
          cin.clear();
          cin.ignore(200, '\n');           
          cout &lt;&lt; x+1 &lt;&lt; ") Input a number: ";
          cin &gt;&gt; num; 
      }
      cout &lt;&lt; "Your Number: " &lt;&lt; num &lt;&lt; endl;
  }
  </code></pre>
  
  <p><strong>Sample Program Input/Output:</strong></p>
  
  <pre><code>1) Input a number: aaa a
  1) Input a number: 50
  Your Number: 50
  2) Input a number: 3a b c 
  Your Number: 3
  3) Input a number: 3) Input a number:   &lt;= How to prevent these duplicated prompts?
  </code></pre>
  
  <p>The codes I used above are acquired from some of the highest voted solutions in past SO posts. However if we give an alpha-numeric input, it will cause a duplicated prompt while prompting for the next input. </p>
  
  <p>Note: The suggested solution is best to avoid functions from C++ 11.</p>
  
  <p><strong>My question is:</strong> How can we overcome this issue?</p>