C++ Cin ignores non-integers? : <p>I have a question about c++. I've been searching for an answer and have found nothing that will fix my code. So I decided to ask myself. My problem is, that I made this little program that will output the day of the week, so if the user inputs 1, it will output the 1st day of the week (Sunday or Monday, depends on where you live) and so on and so forth. However, if the user inputs for example, 8, then the program will output "Please choose a number between 1 and 7!"
However, my problem is that when the user inputs a character or random word, it will loop "Please choose a number between 1 and 7!" forever.</p>

<pre><code>    #include &lt;iostream&gt;
#include &lt;Windows.h&gt;
#include &lt;string&gt;
using namespace std;


int main() {

    int input;


    do {
        cin &gt;&gt; input;
        switch (input) {
        case 1:
            cout &lt;&lt; "Sunday" &lt;&lt; endl;
            break;
        case 2:
            cout &lt;&lt; "Monday" &lt;&lt; endl;
            break;
        case 3:
            cout &lt;&lt; "Tuesday" &lt;&lt; endl;
            break;
        case 4:
            cout &lt;&lt; "Wednesday" &lt;&lt; endl;
            break;
        case 5:
            cout &lt;&lt; "Thursday" &lt;&lt; endl;
            break;
        case 6:
            cout &lt;&lt; "Friday" &lt;&lt; endl;
            break;
        case 7:
            cout &lt;&lt; "Saturday" &lt;&lt; endl;
            break;
        default:
            cout &lt;&lt; "Please choose a number between 1 and 7!" &lt;&lt; endl; // if user chooses a number not from 1-7 output this. But if input is not an int and for example "a", it will loop this forever.
            break;
        }

    } while (true);


    return 0;
}
</code></pre>
