validation - how do I validate user input as a double in C++? -


How do I check that the input is actually a double?

  Double X; While (1) {cout & lt; & Lt; '& Gt;'; If (cin & gt; & gt; x) {// valid number break; } And {// is not a valid coincidence  

The above code infinitely invalid input! outputs the statement, so it is not indicating it for any other input. I want to prompt for input, check whether it is valid ... if it has a double, then proceed. .. if it is not twice, then again sign.

Any thoughts?

Try it out:

  while (1) {if (cin & Gt; & gt; X) {// Valid numbers break; } And {// is not a valid coincidence  

Comments