Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstring>
- #include<iostream>
- using namespace std;
- int main()
- {
- char a[] = "NTOU", b[10];//a為密碼,b為待輸入字串
- for (int i = 0; i < 3; i++)//有三次輸入機會,所以讓for迴圈跑三次
- {
- cout << "請輸入密碼:";
- cin.getline(b, 10);//讀取整行
- if (strcmp(a, b) == 0)//判斷是否正確
- {
- cout << "密碼輸入正確" << endl;
- return 0;//結束程式
- }
- else//錯誤讓for迴圈記續
- cout << "密碼輸入錯誤" <<"請重新輸入密碼"<< endl;
- }
- cout<<"機會用盡\n";
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment