I posted a question about how to get user input, such as YES or NO, to control the flow of the program using if else instructions, I got an answer and now I’m one step closer to doing this work, however there was another problem, I really need to resolve some input, for example, is what I'm trying:
if (input == ("YES" || "yes" || "y" || "Yes" || "Y"))
{
cout << "you said yes" << endl;
}
else if (input == "NO", "no", "n", "No","N")
{
cout << "you said no" << endl;
}
else
{
cout << "ERROR!!!" << endl;
}
Kirill Kirov posted this code that could help:
if( std::string::npos != input.find( "no" ) )
but I could not get it to work, and Mr. Roger suggested the following:
if (prompt && cin.tie()) {
*cin.tie() << prompt << (default_yes ? " [Yn] " : " [yN] ");
however, I have never tried this, since its complexity far exceeds my understanding. I was hoping for a solution that a novice programmer could understand, or maybe just a very slow student
EDIT:
, , , (), , (, NO N no No):
cout << "\nYES or NO" << endl;
string input ="";
cin >> input;
if ( std::string::npos != input.find( "yes" ) )
{
cout << "you said yes" << endl;
}
else if ( std::string::npos != input.find( "no" ) )
{
cout << "you said no" << endl;
}
else
{
cout << "ERROR!!!" << endl;
}