前往
大廳
主題

C/C++紀錄extra(4).<<寫密碼程式,char型態,strcmp函式與迴圈的運用>> 2018/9/10

艾倫D索妮雅 | 2021-06-08 19:48:33 | 巴幣 0 | 人氣 196

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
int i=0;
char code[10];
char password[10];
cout<<"請設定密碼:";
gets(password);
cout<<endl;
cout<<"請輸入密碼:";
do
{
i++;
gets(code);
cout<<endl;
if(strcmp(code,password)==0)
{
break;
}
else if(i==3)
{
cout<<"密碼錯誤!!"<<endl;
cout<<"連續三次錯誤 結束執行"<<endl;
exit(0);  
}
else
{
cout<<"密碼錯誤 請再輸入一次"<<endl;
}
}
while(1);
cout<<"登入帳號中...請稍後"<<endl;
return 0;
}

創作回應

更多創作