如何根据登录名制作单独的菜单
How to make seperate menus that work based on the login
所以对于我正在制作的程序,我想登录两个不同的菜单,然后返回登录。我现在不知道如何处理它。
它像这样:
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:对不起,忘记了循环:)
相关文章:
- 如何在C++中从两个单独的for循环中添加两个数组
- 用C++在单独的头文件中完成函数体
- 类模板的成员功能的定义在单独的TU中完全专业化
- 无法获取菜单选择以运行函数.C++
- 如何使用单独文件中的派生类访问友元函数对象
- CoInitialize()在单独的线程上崩溃而不返回
- avrogencpp能为模式中的每种类型生成单独的头文件吗
- 转换函数,将 std::数组的双精度作为参数或双精度作为参数单独转换
- 单独定义模板化嵌套类方法的正确语法
- 如何将 2 个类分成单独的 .h 文件并正确设置它们
- C++ 链接到单独的.cpp文件说"multiple definitions"
- 从单独的文件中读取树
- 将字符串拆分为标记,并将标记拆分为两个单独的数组
- C++计算器,不能单独除以 0
- C++ 中的图形菜单
- C++ 程序菜单使用做同时和切换
- 自 Windows 10 20H1 以来,具有单独线程的多个窗口停止工作
- 我正在尝试创建一个菜单,但我的代码一直在循环
- 如何根据登录名制作单独的菜单
- 在单独的 GUI 类(菜单、工具栏等)之间共享操作的最佳方式是什么