Question: bool readYN() { char yn; bool done = false; bool result = false; while (!done) { std::cin >> yn; if (yn == 'Y' || yn

 bool readYN() { char yn; bool done = false; bool result = false; while (!done) { std::cin >> yn; if (yn == 'Y' || yn == 'y') { done = true; result = true; } else if (yn == 'N' || yn == 'n') { done = true; result = false; } else { std::cout << "Invalid response, only (Y)es or (N)o are acceptable, retry: "; } std::cin.clear(); std::cin.ignore(100, ' '); } return result; }

How can I change the code to let the input only accept the Y,N,y,n Because, when I type yes or Yes, or Nafafafafaf It still work

Thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!