#include<stdio.h>
#include<stdio.h>
int ligin() /*输入密码登录系统,若三次输入不正确,则退出*/
{
char secretCode[7], ch;
int i, number = 3;
printf("\n\n\n");
printf("\t\t\t* * * * * * 使用学生成绩管理系统 * * * * * * * \n");
printf("\n\n");
while (number > 0)
{
i = 0;
printf("\n\t\t\t请输入密码:");
while ((ch = getch()) != 13)
{
secretCode[i++] = ch;
printf("*");
}
secretCode[i] = '\0';
if (strcmp(secretCode, "888888") == 0)break;
else
{
number--;
if (number <= 0)break;
printf("\n\n\t\t\t 您还有%d次机会\n", number);
}
}
if (number > 0)return 1;
else return 0;
}
mainMenu() /*系统主菜单,需要以后添加*/
{
system("cls");
printf("\n\n\n\t\t\t* * * * * 学生成绩管理系统 * * * * * \n");
getch();
}
main()
{
if (!login())
{
printf("\n\n\t\t很遗憾,您下次再来!\n");
return 1;
}
do
{
mainMenu();
} while (1);
}
代码修改如下
#include<stdio.h>
#include <string.h>
#include <conio.h>
#include <process.h>
int login() /*输入密码登录系统,若三次输入不正确,则退出*/
{
char secretCode[7], ch;
int i, number = 3;
printf("\n\n\n");
printf("\t\t\t* * * * * * 使用学生成绩管理系统 * * * * * * * \n");
printf("\n\n");
while (number > 0)
{
i = 0;
printf("\n\t\t\t请输入密码:");
while ((ch = getch()) != 13)
{
secretCode[i++] = ch;
printf("*");
}
secretCode[i] = '\0';
if (strcmp(secretCode, "888888") == 0)break;
else
{
number--;
if (number <= 0)break;
printf("\n\n\t\t\t 您还有%d次机会\n", number);
}
}
if (number > 0)return 1;
else return 0;
}
void mainMenu() /*系统主菜单,需要以后添加*/
{
system("cls");
printf("\n\n\n\t\t\t* * * * * 学生成绩管理系统 * * * * * \n");
getch();
}
int main()
{
if (!login())
{
printf("\n\n\t\t很遗憾,您下次再来!\n");
return 1;
}
do
{
mainMenu();
} while (1);
return 0;
}
getch() 函数 头文件:#include<conio.h>
第4行函数定义:int ligin() , 第42行函数调用: if (!login()) ,这里函数名错误,两者应该一致。