Question: Write a menu program in C++ that lets the user select from a list of options, and if the input is not one of the options, reprint the list.

I have tried the following code but it is not giving the correct result. Please help.

```
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string j;
    string x = "1. Option 1";
    string x1 = "2. Option 2";
    string x2 = "3. Option 3";
    cout << "please select from the menu " << endl;
    cout << x << endl;
    cout << x1 << endl;
    cout << x2 << endl;
    cin >> j;

    if(j == x)
    {
        cout << "You have selected the option " << j;
    }
    else if(j == x1)
    {
        cout << "if - x1 = You have selected the option " << j;
    }
    else
    {
        cout << "if - x2 = You have selected the option " << j;
    }
}

```

Answer: 
In line:

```
if(j == x)

```

you are comparing user input in `j` with entire string:

```
"1. Option 1"

```

What you want is to compare it with option number:

```
if(j == "1")

```

or:

```
else if(j.size() >= 1 && j[0] == x1[0])
{
    cout << "if - x1 = You have selected the option " << j;
}

```

if you will make sure that first character of your menu strings are identifiers to choose this menu.

Also, the last `else` with no condition is where you should reprint the list of options.
Do something like

```
int MAX_OPTION = 3; // number of options
int option = -1;
while (option < 1 || option > MAX_OPTION) {
    // print the options...
    // get input and store into option
}
// continue with program after input checked

```