title: While loop isn't working when user inputs letters instead of integers?
body: <p>I'm learning c++ on my own and don't have a teacher.</p>
  
  <p>I've created a program that asks the user to enter their password over and over again until they enter the right password. It works, unless the user enters letters instead of integers. It just creates an infinite loop.</p>
  
  <p>Could someone take a look at it and tell me what's wrong with it? Thank you!</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      int password= 123456;
  
      cout&lt;&lt; "Enter your password: "&lt;&lt; flush;
      int input;
      cin&gt;&gt; input;
  
      while(input!=password) {
          cout&lt;&lt; "Access denied."&lt;&lt; endl;
          cout&lt;&lt; "Enter your password: "&lt;&lt; flush;
          cin&gt;&gt; input;
      }
  
      cout&lt;&lt; "Access granted."&lt;&lt; endl;
  
      return 0;
  }
  </code></pre>