有大佬帮我看一下这这一道C语言不,哪里错了一直输入不了?

程序功能:建立一个单向链表,头指针是list,链表中每个结点包含姓名、基本工资信息,编写count_list函数统计链表中超过平均基本工资的人数。要求在主函数中建立单向链表(注:当输入基本工资为0时,表示输入结束。),然后调用count_list函数统计链表中超过平均基本工资的人数,最后输出统计结果和平均基本工资。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct worker{
char name[20];
int money;
struct worker *next;
};

void main()
{
struct worker *list=NULL,*p1=NULL,*p2=NULL;
int n=0,money,sum=0,count;
char name[20];
int count_list(struct worker *list,int avg);
printf("输入工人的姓名与基本工资:\n");
scanf("%s%d",name,&money);

while(money!=0);
{

if((p1=(struct worker *)malloc(sizeof(struct worker)))!=NULL)
{
n++;sum+=money;
strcpy(p1->name,name);
p1->money=money;
p1->next=NULL;
}
else exit(0);

if(n==1) list=p1;
else p2->next=p1;
p2=p1;

scanf("%s%d",name,&money);
}
sum=sum/n;
count=count_list(list,sum);

printf("超过平均工资的人数:%d、平均基本工资为%d:\n",count,sum);

}

int count_list(struct worker *list,int avg)
{
int count=0;
while(list!=NULL)
{ if(list->money>avg) count++;
list=list->next;
}
return count;
}

第1个回答  2020-05-17
while(money!=0);
相似回答