Requiring valid input with cout/cin
<p>I have a game where the user needs to enter x and y coordinates within a certain range, one at a time. Right now my input code is as follows:</p>

<pre><code>do {
    printf("\n");
    cout &lt;&lt; "X: ";
    cin &gt;&gt; x;
    cout &lt;&lt; "Y: ";
    cin &gt;&gt; y;
} while (cin.fail());
</code></pre>

<p>I'm new to c++ but reading documentation lead me to believe this was an acceptable method for verifying user input. It works perfectly when the input is valid, however when the input is of a different type (for instance entering "a") it infinitely loops with "X: Y: ". What do I need to do differently to have it wait for user input as if the lines were being read for the first time?</p>
