利用C语言设计开发小型的员工工资管理信息系统。
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#define N 3
int n=0;
typedef struct employee
{
long num; /*工号*/
char name[50]; /*名字*/
int age; /*年龄*/
char department[10]; /*部门*/
int salary;/*工资*/
}EMPLOYEE;
int selectmenu();
void input(EMPLOYEE employee[]); /*输入*/
void output(EMPLOYEE employee[]); /*输出*/
void inquire(EMPLOYEE employee[]); /*查询*/
int search(EMPLOYEE employee[],int n,long x);
EMPLOYEE employee[N];
void main()
{
int password=123456;
int q;
int w;
printf("你只有一次录入密码的机会\n");
printf("\n\n请输入密码:");
scanf("%d",&w);
printf("\n");
if(password==w)
{
q=selectmenu();
while(1)
{
switch(q)
{
case 1:
input(employee); break; /*输入输入员工信息*/
case 2:
output(employee); break; /*显示员工信息*/
case 3:
inquire(employee); break; /*输入员工卡号来查询员工信息*/
/*根据员工年龄来进行排序 */
case 0:
exit(0); break; /*退出*/
}
q=selectmenu();
}
}
else
printf("输入密码错误!\n");
}
int selectmenu() /*菜单栏*/
{
int q;
printf("\n\n_________________________________________________________\n\n");
printf("\n\n 选择栏 \n\n");
printf("\t\n----------------------------------------------------------------------------\n");
printf("\t\n********1.输入员工信息 ********");
printf("\t\n********2.显示员工信息 ********");
printf("\t\n********3.输入员工卡号来查询员工信息 ********");
printf("\t\n********4.根据员工年龄来进行排序 ********");
printf("\t\n********0.退出程序 ********");
printf("\t\n----------------------------------------------------------------------------\n");
printf("\t请选择菜单号(0--4):");
while((!scanf("%d",&q)||(q<0)||(q>4)))
{
printf("输入有误,请重新输入");
printf("\n\n_________________________________________________________\n\n");
printf("\n\n 选择栏 \n\n");
printf("\t\n----------------------------------------------------------------------------\n");
printf("\t\n********1.输入员工信息 ********");
printf("\t\n********2.显示员工信息 ********");
printf("\t\n********3.输入员工卡号来查询员工信息 ********");
printf("\t\n********4.根据员工年龄来进行排序 ********");
printf("\t\n********0.退出程序 ********");
printf("\t\n----------------------------------------------------------------------------\n");
printf("\t请选择菜单号(0--4):");
}
return q;
}
void input(EMPLOYEE employee[])
{
int n;
printf("\n有多少名员工:");
scanf("%d",&n);
do
{
printf("\n输入员工工号(按0结束录入):");
scanf("%ld",&employee[n].num);
if(employee[n].num==0) break;
for(int i=0;i<n;i++)
{
while(employee[n].num==employee[i].num)
{
printf("\n该员工已经录入,请重新录入:");
scanf("%ld",&employee[n].num);
if(employee[n].num==0) break;
}
printf("\n输入员工姓名:");
scanf("%s",&employee[i].name);
printf("\n输入员工年龄:");
scanf("%d",&employee[i].age);
if((employee[i].age<18)||(employee[i].age>60))
{
printf("\n员工年龄超出年龄范围18-60岁,请重新输入:");
scanf("%d",&employee[i].age);
}
printf("\n输入员工工作部门:");
scanf("%s",&employee[i].department );
printf("\n输入员工工资:");
scanf("%d",&employee[i].salary);
n++;
}
printf("\n");
}while(n<=20);
printf("\n\n-------------------------------------------------------------\n\n");
}
void output(EMPLOYEE employee[])
{
printf("\n\n-------------------------------------------------------------\n\n");
printf("\n 员工信息 \n\n\n");
printf("工号\t姓名\t年龄\t部门\t工资\t\n");
for(int i=0;i<n;i++)
{
printf("%ld\t%s\t%d\t%s\t%d\t",employee[n].num,employee[n].name,employee[n].age,employee[n].department,employee[n].salary);
}
printf("\n\n-------------------------------------------------------------\n\n");
}
void inquire(EMPLOYEE employee[])
{
long x;
printf("输入员工卡号:");
scanf("%ld",&x);
int p;
p=search(employee,n,x);
if(p!=-1)
{
printf(" 员工姓名:%s\t\n",employee[p].name);
printf(" 员工年龄:%d\t\n",employee[p].age );
printf(" 员工部门:%s\t\n",employee[p].department );
printf(" 员工工资:%d\t\n",employee[p].salary );
}
else
{
printf("没有此员工信息");
}
}
int search(EMPLOYEE employee[],int n,long x)
{
int i;
for(i=0;i<n;i++)
{
if(employee[i].num==x)
return(i);
}
return -1;
}
想编一套员工工资管理系统,但是好像出了问题,求大神帮我看看,哪里有问题。没出错误