Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include<cstring>
- using namespace std;
- int main()
- {
- char account[20],password[20];//待輸入的帳號密碼
- char account_1[]="abc",password_1[]="123";//正確的帳號密碼
- for(int i=0;i<3;i++)
- {
- //輸入帳號
- cout<<"Account: ";
- cin.getline(account, 10);
- //輸入密碼
- cout<<"Password: ";
- cin.getline(password, 10);
- if(strcmp(account,account_1)!=0)//如果帳號不相同
- {
- cout<<"wrong account\n";//輸出帳號錯誤
- continue;//跳至for迴圈繼續
- }
- else if(strcmp(password,password_1)!=0)//如果密碼不相同
- {
- cout<<"wrong password\n";//輸出密碼錯誤
- continue;//跳至for迴圈繼續
- }
- else//如果沒有發生上面兩個狀況則是帳號密碼皆正確
- {
- cout<<"login success\n";//輸出成功登入
- return 0;//程式結束
- }
- }
- cout<<"try too many times...\n";
- return 0;
- }
Add Comment
Please, Sign In to add comment