All I want to do, is prompt a user for a yes or no answer, and validate this to ensure they haven't typed something stupid.

I thought this would be a relatively straight forward task, however after many failed attempts at it myself, and looking around online, it seems everyone has a different opinion on the best way to do it.

**Pseudocode**

1. Ask question
2. prompt user
3. check if input = yes or input = no
4. if yes, do scenario a
5. in no, do scenario b
6. if invalid, return to point 2

**Code**

*main.cpp*

```
std::cout << "Do you have a user name? ("yes", "no"): ";
std::cin >> choice;
user.validation(choice);

if (choice == "yes")
{
// some code
}

if (choice == "no")
{
// some code
}

```

*User.cpp*

```
void User::validation(std::string choice)
{
    while (choice != "yes" && choice != "no")
    {       
        std::cout << "Error: Please enter 'yes' or 'no': ";
        std::cin >> choice;
        if (choice == "yes" && choice == "no")
        {
            break;
        }

    }
}

```

This works, up until they eventually type yes or no, when it jumps past if yes, and if no, straight onto the next part of the program

And I want to be able to call user.validation multiple times throughout the program to validate other yes/no questions