title: C++ input failure: multiple inputs in a single statement
body: <p>My C++ professor is adamant that when checking for input failure, one must use separate <code>while()</code> loops for each individual input.  He indicated that the following method of checking more than one input gathered in a single <code>cin</code> statement would not work:</p>
  
  <pre><code>while (!good){
      cout &lt;&lt; "Enter the length and the width of the rectangle: ";
      cin &gt;&gt; length &gt;&gt; width;
      if(!cin){
          cout &lt;&lt; "Bad input, try again" &lt;&lt; endl;
          cin.clear();
          cin.ignore(200, '\n');}
      else {
          good = true;}}
  </code></pre>
  
  <p>His proposed method:</p>
  
  <pre><code>bool good = false;
  while (!good){
      cout &lt;&lt; "Enter the length rectangle: ";
      cin &gt;&gt; length;
      if(!cin){
          cout &lt;&lt; "Bad input, try again" &lt;&lt; endl;
          cin.clear();
          cin.ignore(200, '\n');}
      else {
          good = true;}}  
  while (good){
      cout &lt;&lt; "Enter the width rectangle: ";
      cin &gt;&gt; width;
      if(!cin){
          cout &lt;&lt; "Bad input, try again" &lt;&lt; endl;
          cin.clear();
          cin.ignore(200, '\n');}
      else {
          good = false;}}
  </code></pre>
  
  <p>My method above seems to work just fine.  If non-numerical characters are inputted for either of the inputs, the loop will prompt for new input and clear the fail-state.</p>
  
  <p>Is it simply considered bad form to check for input failure as I have done? I'm hoping to learn more clearly <em>why</em> my method is erroneous.  If my method is faulty, is there a way to check for input failure without using separate loops for every single user-input?  I mainly ask because I'm writing a program that involves getting many inputs from a file, and individually checking each variable seems overly tedious.  I'm thinking there must be a better way.</p>