求助:编写口令检查程序
编写口令检查程序,正确口令为hello。 1、若输入正确,提示“You are welcome”,程序结束。 2、若不正确,提示“Wrong password!”,同时检查口令是否已输3次,若未,提示“Enter again:”,且允许再输入口令,若已输入3次,则提示“You have entered three times!You are not welcome!”,且不允许用户再输入口令,结束程序。
#include #include void main() { int i = 1; char str[20]; printf("Enter password:"); gets(str); while ((i < 3) && (strcmp(str, "hello") != 0)) { i++; printf("Wrong password! Enter again:"); gets(str); } if (strcmp(str, "hello") == 0) printf("You are welcome!\n"); else printf("Wrong password! You have entered three times! You are not welcome!\n"); }