mardi 28 septembre 2021

if and else user verification issue

int main()
{
    int account_or_not;
    account obj;
    menu menu_obj;

    cout << "Do you have an account? 1 for yes or 2 for no " << endl;
    cin >> account_or_not;


    if (account_or_not == 1)
    {
        menu_obj.user_menu();
    }
    else if (account_or_not == 2)
    {
        obj.create_account();
    }
    else
    {
        cout << "You entered a value other than 1 or 2 please try again "<< endl;
        cin >> account_or_not;
    }
  
    return 0;
}

This is what is in the main of my code, and im not sure if I am being dumb, but I have tried a switch case and if else and in the else (or default for switch) when I check what the user has entered was wrong and prompt them to enter it again the program ends when they enter the correct value. E.g if 3 was entered it would tell the user to try again, then when 1 or 2 is entered the program ends. Any ideas, thanks in advance.

Aucun commentaire:

Enregistrer un commentaire