帮忙找错,十分感谢
#include<stdio.h>#define N 10
extern int i,xuehao1;
struct fen
{
float gaoshu1;
float cyuyan1;
float tiyu1;
float yingyu1;
float zhongguogemingshi1;
};
struct student
{
char name;
int xuehao;
float gaoshu;
float cyuyan ;
float tiyu ;
float yingyu;
float zhongguogemingshi ;
float average ;
structfen xuefen;
}stu;
void found( int n);
float ave(float stu.gaoshu,float stu.cyuyan,float stu.tiyu,float stu.yingyu,float stu.zhongguogemingshi);
main()
{
float zongxuefen;
float average;
int xuehao1;
int j,ave,a=0,b=0,c=0,d=0;
float t;
char degree;
printf("请依次分别输入学生的姓名,高等数学,c语言程序设计,体育,英语,中国革命史成绩");
for(i=0;i<N;i++)
{
scanf("%c",&stu.name);
scanf("%f",&stu.gaoshu);
scanf("%f",&stu.cyuyan);
scanf("%f",&stu.tiyu);
scanf("%f",&stu.yingyu);
scanf("%f",&stu.zhongguogemingshi);
}
for(i=0;i<N;i++)
{
if(stu.gaoshu>=60)
stu.xuefen.gaoshu1=5;
else
stu.xuefen.gaoshu1=0;
if(stu.cyuyan>=60)
stu.xuefen.cyuyan1=3.5;
else
stu.xuefen.cyuyan1=0;
if(stu.tiyu>=60)
stu.xuefen.tiyu1=2;
else
stu.xuefen.tiyu1=0;
if(stu.yingyu>=60)
stu.xuefen.yingyu1=3;
else
stu.xuefen.yingyu1=0;
if(stu.zhongguogemingshi>=60)
stu.xuefen.zhongguogemingshi1=2;
else
stu.xuefen.zhongguogemingshi1=0;
average=ave(stu.gaoshu,stu.cyuyan,stu.tiyu,stu.yingyu,stu.zhongguogemingshi);
zongxuefen=stu.xuefen.gaoshu1+stu.xuefen.cyuyan1+stu.xuefen.tiyu1+stu.xuefen.yingyu1+stu.xuefen.zhongguogemingshi1;
}
for(i=0;i<N;i++)
{
if(ave<60)
degree='D';
if(60<=ave&&ave<75)
degree='C';
if(75<=ave&&ave<90)
degree='B';
if(90<=ave&&ave<=100)
degree='A';
switch(degree)
{
case 'A':a++;
case 'B':b++;
case 'C':c++;
case 'D':d++;
}
}
printf("在分数段0~60的人有%d个\n",d);
printf("在分数段60~75的人有%d个\n",c);
printf("在分数段75~90的人有%d个\n",b);
printf("在分数段90~100的人有%d个\n",a);
printf("--------------------------------------------------");
printf("请输入要查找的学生的学号");
scanf("%d",&xuehao1);
found(xuehao1);
for(i=0;i<9;++i)
{
for(j=0;j<9-i;++j)
{
if(zongxuefen>zongxuefen)
{
t=zongxuefen;
zongxuefen=zongxuefen;
zongxuefen=t;
}
}
}
for(j=0;j<10;++j)
{
printf("%-5d\n ",zongxuefen);
}
}
float ave(float stu.gaoshu,floatstu.cyuyan,floatstu.tiyu,floatstu.yingyu,floatstu.zhongguogemingshi)
{
float sum;
sum=(stu.gaoshu + stu.cyuyan + stu.tiyu + stu.yingyu + stu.zhongguogemingshi);
return sum/5;
}
void found(int xuehao1)
{
for(i=0;i<N;i++)
{
if((xuehao1-stu.xuehao)==0)
printf("名字:%c\n 高数成绩:%f\n c语言成绩:%f\n 体育成绩:%f\n 英语成绩:%f\n 中国革命史:%f\n",stu.name,stu.gaoshu,stu.cyuyan,stu.tiyu,stu.yingyu,stu.zhongguogemingshi);
}
}
目前修改后的代码已经可以运行,你的具体需求没有写明,所以就只帮你修改了一些错误{:10_257:}
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define N 10
extern int i, xuehao1;
struct fen
{
float gaoshu1;
float cyuyan1;
float tiyu1;
float yingyu1;
float zhongguogemingshi1;
};
struct student
{
char name;
int xuehao;
float gaoshu;
float cyuyan;
float tiyu;
float yingyu;
float zhongguogemingshi;
float average;
structfen xuefen;
};
void found(struct student stu,int n);
float ave(struct student stu,int i);
int main()
{
struct student stu;
float zongxuefen;
float average;
int i;
int xuehao1;
int j, a = 0, b = 0, c = 0, d = 0;
float t;
char degree;
printf("请依次分别输入学生的姓名,高等数学,c语言程序设计,体育,英语,中国革命史成绩:\n");
for (i = 0; i < N; i++)
{
scanf("%c", &stu.name);
scanf("%f", &stu.gaoshu);
scanf("%f", &stu.cyuyan);
scanf("%f", &stu.tiyu);
scanf("%f", &stu.yingyu);
scanf("%f", &stu.zhongguogemingshi);
}
for (i = 0; i < N; i++)
{
if (stu.gaoshu >= 60)
stu.xuefen.gaoshu1 = 5;
else
stu.xuefen.gaoshu1 = 0;
if (stu.cyuyan >= 60)
stu.xuefen.cyuyan1 = 3.5;
else
stu.xuefen.cyuyan1 = 0;
if (stu.tiyu >= 60)
stu.xuefen.tiyu1 = 2;
else
stu.xuefen.tiyu1 = 0;
if (stu.yingyu >= 60)
stu.xuefen.yingyu1 = 3;
else
stu.xuefen.yingyu1 = 0;
if (stu.zhongguogemingshi >= 60)
stu.xuefen.zhongguogemingshi1 = 2;
else
stu.xuefen.zhongguogemingshi1 = 0;
average = ave(stu,i);
zongxuefen = stu.xuefen.gaoshu1 + stu.xuefen.cyuyan1 + stu.xuefen.tiyu1 + stu.xuefen.yingyu1 + stu.xuefen.zhongguogemingshi1;
}
for (i = 0; i < N; i++)
{
if (average < 60)
degree = 'D';
if (60 <= average && average < 75)
degree = 'C';
if (75 <= average && average < 90)
degree = 'B';
if (90 <= average && average <= 100)
degree = 'A';
switch (degree)
{
case 'A':a++;
case 'B':b++;
case 'C':c++;
case 'D':d++;
}
}
printf("在分数段0~60的人有%d个\n", d);
printf("在分数段60~75的人有%d个\n", c);
printf("在分数段75~90的人有%d个\n", b);
printf("在分数段90~100的人有%d个\n", a);
printf("--------------------------------------------------\n");
printf("请输入要查找的学生的学号:\n");
scanf("%d", &xuehao1);
found(stu,xuehao1);
for (i = 0; i < 9; ++i)
{
for (j = 0; j < 9 - i; ++j)
{
if (zongxuefen > zongxuefen)
{
t = zongxuefen;
zongxuefen = zongxuefen;
zongxuefen = t;
}
}
}
for (j = 0; j < 10; ++j)
{
printf("%-5lf\n ", zongxuefen);
}
return 0;
}
float ave(struct student stu,int i)
{
float sum;
sum = (stu.gaoshu + stu.cyuyan + stu.tiyu + stu.yingyu + stu.zhongguogemingshi);
return sum / 5;
}
void found(struct student stu,int xuehao1)
{
int i;
for (i = 0; i < N; i++)
{
if ((xuehao1 - stu.xuehao) == 0)
printf("名字:%s\n 高数成绩:%f\n c语言成绩:%f\n 体育成绩:%f\n 英语成绩:%f\n 中国革命史:%f\n", stu.name, stu.gaoshu, stu.cyuyan, stu.tiyu, stu.yingyu, stu.zhongguogemingshi);
}
} Tec 发表于 2019-12-17 21:20
目前修改后的代码已经可以运行,你的具体需求没有写明,所以就只帮你修改了一些错误
非常感谢你,我还想问以下第一行的是什么东西{:5_109:} 我的编译器使用scanf函数会提示 _CRT_SECURE_NO_WARNINGS 警告,建议我使用新版本的scanf_s函数,原因是这些函数不安全,可能会造成内存泄露等
第一行是宏定义,可以忽略这些警告
页:
[1]