天天看點

c語言int total,新人求教C語言type mismatch in redeclaration of‘total’

該樓層疑似違規已被系統折疊 隐藏此樓檢視此樓

這個程式 運作時報錯 出現

type mismatch in redeclaration of‘total’ 怎麼解決?

#include

#include

#include

#define num 10

typedef struct employee{

int age;

char *name;

double salary;

}*PEMP;

void update(PEMP*,int,int,char*,double);

double total(PEMP*);

double mean(PEMP*);

void readin(PEMP*);

void main()

{PEMP company[num];

double x;

int i;

readin(company);

for(i=0;i

printf("%s\t%d\t%d\t%d\t%lf\n",company[i]->age,company[i]->salary);

x=total(company);

printf("total=%8.2f\n",x);

printf("mean=%g\n",mean(company));

}

void update(PEMP company[],int id,int age,char*name,double salary)

{PEMP emp;

if((emp=(PEMP)malloc(sizeof(struct employee)))==NULL)

return 0;

emp->age=age;

emp->salary=salary;

emp->name=name;

company[id]=emp;

}

double total(PEMP company[],int n)

{

int i,age1,age2;

double sum=0;

for(;;)

{

printf("Please input the age range:") ;

scanf("%d%d",&age1,&age2);

if(age1>age2)

{i=age1;age1=age2;age2=i;}

if((age1<=0)&&(age1<=70)&&(age2>=0)&&(age2<=70)&&(age2>age1)) break;

}

for(i=0;i

if(company[i]!=NULL&&(company[i]->age)>=age1&&(company[i]->age<=age2))

sum+=(company[i]->salary);

return(sum);

}

double mean(PEMP company[])

{ int i;

char ch; int age=0;int n=0;double sum=0;

printf("Calculate specific age range salary:\n");

printf("All emploees salary/y\n:");

getchar(); ch=getchar();

if(ch=='Y'||ch=='y')

{

printf("age:");

scanf("%d",&age);}

for(i=0;i

if(company[i]!=NULL&&(company[i]->age)>=age)

{sum+=(company[i]->salary);++n;}

printf("age=%d,sum=%f\n",age,sum);

sum=sum/n;

return(sum);

}