title: (C++) How to validate user input for char variables?
body: <p>I'm having trouble comparing user input for a char variable. I want to check if they answered Y or N to a question. If they did not put a Y or N I want to give the user an error message and start the loop over. </p>
  
  <p>Below is the test code I created as a template for the program I intend to use it for.
  The program loops no matter what input the user gives. Also, if the user inputs 'n' characters, they will receive 'n' "Failure!" messages along with the initial cout message each time. If they input Y it happens as well except of course it says "Success!".</p>
  
  <p>I've looked around online but have yet to find anyone address this. Why does == work for equivalency checks but not != for chars (and strings as well for that matter)? </p>
  
  <pre><code>#include&lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      char answer;
  
      do{
          cout &lt;&lt;"\nPlease type Y or N." &lt;&lt; endl;
          cin &gt;&gt; answer;
  
          if ((answer == 'Y') || (answer == 'N'))
          {
              cout &lt;&lt; "\nSuccess!" &lt;&lt; endl;
          }
          else
          {
              cout &lt;&lt; "\nFailure!" &lt;&lt; endl;
          }
      }while ((answer != 'Y') || (answer != 'N'));
  
      return 0;
  }
  </code></pre>