c语言输入三次密码错误跳回主界面
时间: 2023-12-16 08:02:33 浏览: 32
以下是一个简单的示例代码,当输入密码错误达到三次时,程序会跳回主界面。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char password[10];
int count = 0;
int choice;
do {
printf("Please enter password: ");
scanf("%s", password);
if (strcmp(password, "123456") == 0) {
printf("Welcome to the system!\n");
break;
} else {
count++;
printf("Wrong password, please try again.\n");
}
if (count == 3) {
printf("You have entered the wrong password too many times.\n");
break;
}
} while (1);
if (count == 3) {
printf("Returning to main menu...\n");
printf("1. Login\n");
printf("2. Exit\n");
printf("Please enter your choice: ");
scanf("%d", &choice);
}
return 0;
}
```