如何根据登录名制作单独的菜单

How to make seperate menus that work based on the login

本文关键字:单独 菜单 何根 登录      更新时间:2023-10-16

所以对于我正在制作的程序,我想登录两个不同的菜单,然后返回登录。我现在不知道如何处理它。

它像这样:

    string User;
    string Pass;
    int Option;
    void Login(){
        cout << "Enter your username: ";
        cin >> User;
        cout << "Enter your password: ";
        cin >> Pass;
    }
    void Admin(){
        system("CLS");
        cout << "Welcome Admin" << endl;
        cout << "------------" << endl;
        cout << "1. Do something" << endl;
        cout << "2. Do something else" << endl;
        cout << "3. Log out" << endl;
        cout << "4. Quit Program" endl;
        cin >> Option;
    }
    void User(){
        system("CLS");
        cout << "Welcome User" << endl;
        cout << "------------" << endl;
        cout << "1. Do another thing" << endl;
        cout << "2. Do something other things don't do" << endl;
        cout << "3. Log out" << endl;
        cout << "4. Quit Program" endl;
        cin >> Option;
}
        int main(){
        Login();
        if(User == "admin" && Pass == "admin"){
                Admin();
                if(Option == 3){
                // What should I add here if would want to return to login then to user menu
                }
        }
        else
        User();
}

好吧,如果你想返回登录菜单,你可以使用一个循环:

int main()
{
    while(1)
    {
        Login();
        if(User == "admin" && Pass == "admin")
        {
            Admin();
        }
        else
        {
            User();
        }
        if(Option == 3) continue;
        if(Option == 4) break;
    }
    return 0;
}

UPD:对不起,忘记了循环:)