【C學習筆記】day5-3 編寫代碼模擬三次密碼輸入的場景
3.編寫代碼模擬三次密碼輸入的場景。 最多能輸入三次密碼,密碼正確,提示“登錄成功”,密碼錯誤, 可以重新輸入,最多輸入三次。三次均錯,則提示退出程序。
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <string.h> int main() { char password[16] = {"123456 "}; char password_input[16]; int n=0; while (~scanf("%[^\n]%*c", password_input)) { if (strcmp(password_input, password) == 0) { printf_s("right!\n"); break; } else { n++; if (3 == n) { printf_s("quit!\n"); break; } else { printf_s("error!Please try again!\n"); continue; } } } return 0; }


浙公網安備 33010602011771號