gha890826

大一期中考-5-猜題

Apr 18th, 2020 (edited)
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include<cstring>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     char account[20],password[20];//待輸入的帳號密碼
  9.     char account_1[]="abc",password_1[]="123";//正確的帳號密碼
  10.  
  11.     for(int i=0;i<3;i++)
  12.     {
  13.         //輸入帳號
  14.         cout<<"Account: ";
  15.         cin.getline(account, 10);
  16.         //輸入密碼
  17.         cout<<"Password: ";
  18.         cin.getline(password, 10);
  19.        
  20.         if(strcmp(account,account_1)!=0)//如果帳號不相同
  21.         {
  22.             cout<<"wrong account\n";//輸出帳號錯誤
  23.             continue;//跳至for迴圈繼續
  24.         }
  25.         else if(strcmp(password,password_1)!=0)//如果密碼不相同
  26.         {
  27.             cout<<"wrong password\n";//輸出密碼錯誤
  28.             continue;//跳至for迴圈繼續
  29.         }
  30.         else//如果沒有發生上面兩個狀況則是帳號密碼皆正確
  31.         {
  32.             cout<<"login success\n";//輸出成功登入
  33.             return 0;//程式結束
  34.         }
  35.     }
  36.     cout<<"try too many times...\n";
  37.    
  38.     return 0;
  39. }
Add Comment
Please, Sign In to add comment