2024-12-07 09:00:11 +08:00
|
|
|
//登录系统(升级版)
|
|
|
|
|
2024-11-08 22:19:37 +08:00
|
|
|
#include<iostream>
|
|
|
|
#include<string>
|
|
|
|
#include<windows.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
string username,password;
|
|
|
|
string uname,pwd;
|
|
|
|
|
|
|
|
username = "2022110";
|
|
|
|
password = "246810"; //设置密码和用户名
|
|
|
|
|
|
|
|
cout <<"欢迎使用登录系统(demo)"<<endl; //无
|
|
|
|
|
|
|
|
for (int time = 3; time > 0;time = time - 1) //反复与计数器
|
|
|
|
{
|
|
|
|
int time_out = time -1;
|
|
|
|
cout <<"请输入用户名:"; //输入用户名
|
|
|
|
cin >>uname;
|
|
|
|
cout <<"请输入密码:"; //输入密码
|
|
|
|
cin >>pwd;
|
|
|
|
|
|
|
|
if (uname == username) //验证用户名是否正确
|
|
|
|
{
|
|
|
|
if (pwd == password) //验证密码是否正确
|
|
|
|
{
|
|
|
|
cout <<"用户名与密码正确!亲爱的小朋友欢迎您!"; //密码与用户名正确的处理
|
|
|
|
Sleep(1370);
|
|
|
|
return 0;
|
|
|
|
}else{
|
|
|
|
cout <<"密码错误!你还剩下"<<time_out<<"次机会!"<<endl; //密码错误的处理
|
|
|
|
Sleep(1000);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
cout <<"用户名不正确!你还剩下"<<time_out<<"次机会!"<<endl; //用户名错误的处理
|
|
|
|
Sleep(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cout <<"尝试次数达到最大!"; //登录次数用完了的处理
|
|
|
|
Sleep(1000);
|
|
|
|
return 1;
|
|
|
|
}
|