C++ Logical Operator And Ensure user types a correct response

Description

C++ Logical Operator And Ensure user types a correct response

#include <iostream>
using namespace std;
int main()//  ww w  .j  a  v a  2 s .c o  m
{
   char ans;
   cout << "Do you want to continue (Y/N)? ";
   cin >> ans;                // Get user's answer
   while ((ans != 'Y') && (ans != 'N'))
   {
      cout << "\nYou must type a Y or an N\n";  // Warn and ask
      cout << "Do you want to continue (Y/N)?"; // again.
      cin >> ans;
   }         // Body of while loop ends here.
   return 0;
}



PreviousNext

Related