mardi 10 juillet 2018

Conditional Statement Simplification - C++

What would the best way be of reducing my conditions in this code, is it to simply implement the Boost library for a string comparison or is there another way of doing it? I would much more prefer to avoid using boost if possible.

How could said question be implemented on the following code?

    cout << " Please Enter An Answer Of Yes(Y) or No(N):";
    string question; cin >> question;

    if (question == "yes" || question == "Yes" || question == "Y" || question == "y" || question == "YEs" || question == "YES" || question == "yeS" || question == "yES") 
            {
            cout << "You said yes!" << endl;
            return 1;
            } 
    else if (question == "No" || question == "NO || question == "nO" || question == "N" || question == "n")
            {
            cout << "You said no!" <<endl;
            return 0;
            }  
    else 
            {
            AskAQuestion();
            }

Aucun commentaire:

Enregistrer un commentaire