title: how do I validate user input as a double in C++?
body: <p>How would I check if the input is really a double?</p>
  
  <pre><code>double x;
  
  while (1) {
      cout &lt;&lt; '&gt;';
      if (cin &gt;&gt; x) {
          // valid number
          break;
      } else {
          // not a valid number
          cout &lt;&lt; "Invalid Input! Please input a numerical value." &lt;&lt; endl;
      }
  }
  //do other stuff...
  </code></pre>
  
  <p>The above code infinitely outputs the <code>Invalid Input!</code> statement, so its not prompting for another input. I want to prompt for the input, check if it is legitimate... if its a double, go on... if it is NOT a double, prompt again.</p>
  
  <p>Any ideas?</p>