【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号