title: c++ string validation for user input
body: <p>All I want to do, is prompt a user for a yes or no answer, and validate this to ensure they haven't typed something stupid.</p>
  
  <p>I thought this would be a relatively straight forward task, however after many failed attempts at it myself, and looking around online, it seems everyone has a different opinion on the best way to do it.</p>
  
  <p><strong>Pseudocode</strong></p>
  
  <ol>
  <li><p>Ask question</p></li>
  <li><p>prompt user</p></li>
  <li><p>check if input = yes or input = no</p></li>
  <li><p>if yes, do scenario a</p></li>
  <li><p>in no, do scenario b</p></li>
  <li><p>if invalid, return to point 2</p></li>
  </ol>
  
  <p><strong>Code</strong></p>
  
  <p><em>main.cpp</em></p>
  
  <pre><code>std::cout &lt;&lt; "Do you have a user name? ("yes", "no"): ";
  std::cin &gt;&gt; choice;
  user.validation(choice);
  
  if (choice == "yes")
  {
  // some code
  }
  
  if (choice == "no")
  {
  // some code
  }
  </code></pre>
  
  <p><em>User.cpp</em></p>
  
  <pre><code>void User::validation(std::string choice)
  {
      while (choice != "yes" &amp;&amp; choice != "no")
      {       
          std::cout &lt;&lt; "Error: Please enter 'yes' or 'no': ";
          std::cin &gt;&gt; choice;
          if (choice == "yes" &amp;&amp; choice == "no")
          {
              break;
          }
  
      }
  }
  </code></pre>
  
  <p>This works, up until they eventually type yes or no, when it jumps past if yes, and if no, straight onto the next part of the program</p>
  
  <p>And I want to be able to call user.validation multiple times throughout the program to validate other yes/no questions</p>