gha890826

大一期中考-5

Apr 18th, 2020 (edited)
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<cstring>
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     char a[] = "NTOU", b[10];//a為密碼,b為待輸入字串
  8.  
  9.     for (int i = 0; i < 3; i++)//有三次輸入機會,所以讓for迴圈跑三次
  10.     {
  11.         cout << "請輸入密碼:";
  12.         cin.getline(b, 10);//讀取整行
  13.         if (strcmp(a, b) == 0)//判斷是否正確
  14.         {
  15.             cout << "密碼輸入正確" << endl;
  16.             return 0;//結束程式
  17.         }
  18.         else//錯誤讓for迴圈記續
  19.             cout << "密碼輸入錯誤" <<"請重新輸入密碼"<< endl;
  20.     }
  21.     cout<<"機會用盡\n";
  22.     system("pause");
  23.     return 0;
  24. }
Add Comment
Please, Sign In to add comment