title: While loop not breaking, using cin.ignore and cin.clear() to verify input
body: <p>I'm trying to use a loop to verify that the input grade is an integer, but when I intentionally input a char, the program does nothing. It only starts a newline upon pressing <kbd>enter</kbd>.</p>
  
  <pre><code>void fillvector(vector&lt;student&gt;&amp; parameter)         
  {
  string newname;
  int newgrade;
  int number;
  cout &lt;&lt; "How many students are in your class: ";
  cin &gt;&gt; number;  
  for (int i = 0; i &lt; number; i++)
  {
      cout &lt;&lt; endl &lt;&lt; "Enter student name: ";
      while (1)
      {
          cin &gt;&gt; newname;
          cout &lt;&lt; "Enter student grade: ";
          cin &gt;&gt; newgrade;
          if (cin.fail())                                                         
          {
              cout &lt;&lt; endl &lt;&lt; "Grade must be an integer value, try again.";
              cin.clear();
              cin.ignore(INT_MAX);
              i--;
              break;
          }
          else
          {
              student student(newname, newgrade);
              parameter.push_back(student);
              break;
          }
      }
  }
  cout &lt;&lt; endl;
  } 
  </code></pre>