录入结构,生成链表。
功能简单,我都写在main函数中,如果你写项目,建议按功能拆成多个函数调用。
#include
#include
typedef struct persl
{
int id;
char name[20];
int age;
float bpay;
float x;
float acmt;
struct persl *next;
}PERSL;
int main()
{
int ages=0,cnt=0;
float pays=0,pay=0;
char c;
PERSL *perslTail=NULL,*perslNew=NULL,*perslHead=(PERSL *)malloc(sizeof(PERSL));
perslHead->next=NULL;
printf("录入员工信息\n");
while(1)//---------录入
{
perslNew=(PERSL *)malloc(sizeof(PERSL));
perslNew->next=NULL;
printf("编号:");
scanf("%d",&perslNew->id);
printf("姓名:");
scanf("%s",perslNew->name);
printf("年龄:");
scanf("%d",&perslNew->age);
printf("基本工资:");
scanf("%f",&perslNew->bpay);
printf("系数:");
scanf("%f",&perslNew->x);
printf("业绩:");
scanf("%f",&perslNew->acmt);
if(!perslHead->next)
perslHead->next=perslNew;
else
perslTail->next=perslNew;
perslTail=perslNew;
printf("是否继续录入?Y/N\n");
getchar();
scanf("%c",&c);
if(c=='N')
break;
}
printf("编号 姓名 年龄 基本工资 系数 业绩):\n");
while(perslHead->next)//----------打印
{
cnt++;
ages+=perslHead->next->age;
pay=perslHead->next->bpay+perslHead->next->acmt*0.01*perslHead->next->x;
pays+=pay;
printf("%03d %s %d %f\n",perslHead->next->id,perslHead->next->name,perslHead->next->age,pay);
perslHead=perslHead->next;
}
printf("平均年龄及平均工资:%d,%f\n",ages/cnt,pays/cnt);
return 0;
}