完成上述字符串比较的场景
如果登录失败,提示用户登录失败信息,并且提示错误几次,且重新输入
如果输入错误三次,则退出系统
#include <iostream>
using namespace std;
int main()
{
string name,pswd;
string username = "admin";
string userpswd = "123456";
int num = 3;
while(num--){
cout << "请输入用户名:";
cin >> name;
cout << "请输入密码:";
cin >> pswd;
if(name == username && pswd == userpswd){
cout << "登录成功" << endl;
break;
}
else{
if(num == 0)
{
return 0;
}
cout << "账号或密码输入错误,还剩" << num << "次机会" << endl;
}
}
return 0;
}
思维导图