
c语言,结构体问题。总是提示: syntax error : 'type' 5
#include<stdio.h>#include<stdlib.h>structworker{charname[20];intage;charsex;doublesal...
#include<stdio.h>
#include<stdlib.h>
struct worker{
char name[20];
int age;
char sex;
double salery1;
double salery2;
double salery3;
};
struct worker worker,workers[5]={"zhangsan",30,'F',950,100,100 ,
"lisi",31,'M',2500,1000,100,
"wangwu",45,'M',1000,1000,1000,
"xiaoli",20,'M',900,100,100,
"chutian",24,'F',2000,500,100
};
void menu(){
printf("please input your choose:\n");
printf("1 查找最低收入的员工\n");
printf("2 统计基本工资不到1000元且年龄不高于30岁的女性员工人数\n");
printf("3 exit\n");
}
struct worker min(struct worker w[]){
double sum[5]={0.0};
int i = 0;
int flag=0;
for(; i<5; i++){
sum[i] = w[i].salery1+w[i].salery2+w[i].salery3;
}
for(i=1; i<5; i++){
if(sum[i]<sum[flag])
flag = i;
}
return w[flag];
}
int count(struct worker w[]){
int i=0;
int count = 0;
for(; i<5; i++){
if(w[i].salery1<1000 && w[i].age<=30 && w[i].sex=='F')
count++;
}
return count;
}
void main(){
int k;
double sum;
struct worker worker,workers[5]={"zhangsan",30,'F',950,100,100 ,
"lisi",31,'M',2500,1000,100,
"wangwu",45,'M',1000,1000,1000,
"xiaoli",20,'M',900,100,100,
"chutian",24,'F',2000,500,100
};
while(1){
menu();
scanf("%d", &k);
switch(k){
case 1:
worker = min(workers);
sum = worker.salery1+worker.salery2+worker.salery3;
printf("工资总数最低的员工信息是:\n");
printf("姓名:%s\t年龄:%d\t 性别:%c\n", worker.name,worker.age,worker.sex);
printf("基本工资:%.2f,分红:%.2f,岗位补贴:%.2f, 总额:%.2f\n", worker.salery1,worker.salery2,worker.salery3,sum);
break;
case 2:
printf("基本工资不到1000元且年龄不高于30岁的女性员工人数为:%d\n", count(workers));
break;
case 3:
exit(0);
default:
printf("你输入有误,请重新输入1-3\n");
break;
}
}
} 展开
#include<stdlib.h>
struct worker{
char name[20];
int age;
char sex;
double salery1;
double salery2;
double salery3;
};
struct worker worker,workers[5]={"zhangsan",30,'F',950,100,100 ,
"lisi",31,'M',2500,1000,100,
"wangwu",45,'M',1000,1000,1000,
"xiaoli",20,'M',900,100,100,
"chutian",24,'F',2000,500,100
};
void menu(){
printf("please input your choose:\n");
printf("1 查找最低收入的员工\n");
printf("2 统计基本工资不到1000元且年龄不高于30岁的女性员工人数\n");
printf("3 exit\n");
}
struct worker min(struct worker w[]){
double sum[5]={0.0};
int i = 0;
int flag=0;
for(; i<5; i++){
sum[i] = w[i].salery1+w[i].salery2+w[i].salery3;
}
for(i=1; i<5; i++){
if(sum[i]<sum[flag])
flag = i;
}
return w[flag];
}
int count(struct worker w[]){
int i=0;
int count = 0;
for(; i<5; i++){
if(w[i].salery1<1000 && w[i].age<=30 && w[i].sex=='F')
count++;
}
return count;
}
void main(){
int k;
double sum;
struct worker worker,workers[5]={"zhangsan",30,'F',950,100,100 ,
"lisi",31,'M',2500,1000,100,
"wangwu",45,'M',1000,1000,1000,
"xiaoli",20,'M',900,100,100,
"chutian",24,'F',2000,500,100
};
while(1){
menu();
scanf("%d", &k);
switch(k){
case 1:
worker = min(workers);
sum = worker.salery1+worker.salery2+worker.salery3;
printf("工资总数最低的员工信息是:\n");
printf("姓名:%s\t年龄:%d\t 性别:%c\n", worker.name,worker.age,worker.sex);
printf("基本工资:%.2f,分红:%.2f,岗位补贴:%.2f, 总额:%.2f\n", worker.salery1,worker.salery2,worker.salery3,sum);
break;
case 2:
printf("基本工资不到1000元且年龄不高于30岁的女性员工人数为:%d\n", count(workers));
break;
case 3:
exit(0);
default:
printf("你输入有误,请重新输入1-3\n");
break;
}
}
} 展开
1个回答
2015-05-17
展开全部
能不能发一下详细的错误的截图,我复制了你的源码 在VC6.0中 编译通过,没有任何错误 或者警告。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询