实现用户输入用户名和密码,当用户名为admin或administrator且密码为012345时,显示“登录成功”,否则显示“登录失败”,登录失败时允许重复输入三次。
时间: 2023-05-12 21:07:29 浏览: 77
以下是实现用户输入用户名和密码,当用户名为admin或administrator且密码为012345时,显示“登录成功”,否则显示“登录失败”,登录失败时允许重复输入三次的代码:
```
#include <iostream>
#include <string>
using namespace std;
int main() {
string username, password;
int count = 0;
bool success = false;
while (count < 3 && !success) {
cout << "请输入用户名:";
cin >> username;
cout << "请输入密码:";
cin >> password;
if ((username == "admin" || username == "administrator") && password == "012345") {
cout << "登录成功!" << endl;
success = true;
} else {
cout << "登录失败!" << endl;
count++;
}
}
if (!success) {
cout << "登录失败次数过多,程序退出。" << endl;
}
return 0;
}
```
希望能够帮到你!