当前位置:编程学习 > C/C++ >>

c语言程序改错

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct STUDENT
{int number,english,clanguage,math,linemath,average,t;
char name[20];
}student[41];
void student_new(void)
{int n;
page_title("print in student's new:");
for(n=1;n<41;n++)
{printf("number:");
scanf("%d",&student[n].number);
printf("name:");
scanf("%s",&student[n].name);
}
}
int check_number(void)
{int n,i;
printf("print in student's number:");
scanf("%d",&i);
for(n=1;n<41;n++)
{if(student[n].number==i)
{printf("number:\n",student[n].number);
printf("name:\n",student[n].name);
return n;
}
}
printf("\nprint in wrong or no this number\n");
return -1;
void student_edit(void)
{int n;
page_title("change student's new");
if(n=check_number()!=-1)
{printf("\nprint in new informatian:\n");
printf("number:");
scanf("%d",&student[n].number);
printf("name:");
scanf("%s",&student[n].name);
}
}
printf("\nprint in wrong or no this number\n");
return -1;
}
void score_print(void)
{int n,a,s;
page_title("print in score");
printf("\nuse the number keys to choice the subjict");
printf("\n1 english\n2 math\n3 clanguage\n4 linemath\n");
scanf("%d",&a);
for(n=1;n<41;n++)
{printf("number:%d name:%s score:",student[n].number,student[n].name);
scanf("%d",&s);
switch(a)
{case 1: student[n].english=s;break;
case 2: student[n].math=s;break;
case 3: student[n].clanguage=s;break;
case 4: student[n].linemath=s;break;
}
}
}
void score_edit(void)
{int n;
page_title("change score");
if(n=check_number()!=-1)
{printf("english:%d math:%d clangudge:%d linemath:%d",student[n].english,student[n].math,student[n].language-C,student[n].line-math);
printf("\nprint in score again:\n");
printf("english:");
scanf("%d",&student[n].english);
printf("math:");
scanf("%d",&student[n].math);
printf("language-C:");
scanf("%d",&student[n].clanguage);
printf("line-math:");
scanf("%d",&student[n].linemath);
}
}
void student_del(void)
{int n;
page_title("delete student's new");
if(n=check_number()!=-1)
student[n].number=0;
printf("\nthe student has been deleted\n");
}
}
void student_inc(void)
{int n;
page_title("increase student's new");
if(n=check_number()==-1)
student[n].number+=1;
printf("\nthe student has been increased");
}
void sum(void)
{int n;
int t1=0;int t2=0;
int t3=0;int t4=0;
int t5=0;int t6=0;
int t7=0;int t8=0;
int t9=0;int t10=0;
int t11=0;int t12=0;
int t13=0;int t14=0;
int t15=0;int t16=0;
for(n=1;n<41;n++)
{if(studnet[n].english>=90 && student[n].english<=100)
t1+=1;
else if(student[n].english>=80 && student[n].english<90)
t2+=1;
else if(student[n].english>=60 && studeng[n].english<80)
t3+=1;
else t4+=1;
if(studnet[n].math>=90 && student[n].math<=100)
t5+=1;
else if(student[n].math>=80 && student[n].math<90)
t6+=1;
else if(student[n].math>=60 && studeng[n].math<80)
t7+=1;
else t8+=1;
if(studnet[n].clanguage>=90 && student[n].clanguage<=100)
t9+=1;
else if(student[n].clanguage>=80 && student[n].clanguage<90)
t10+=1;
else if(student[n].clanguage>=60 && studeng[n].clanguage<80)
t11+=1;
else t12+=1;
if(studnet[n].linemath>=90 && student[n].linemath<=100)
t13+=1;
else if(student[n].linemath>=80 && student[n].linemath<90)
t14+=1;
else if(student[n].linemath>=60 && studeng[n].linemath<80)
t15+=1;
else t16+=1;
}
printf("90-100\t\t%d\t%d\t%d\t%d\n",t1,t5,t9,t13);
printf("80-90\t\t%d\t%d\t%d\t%d\n",t2,t6,t10,t14);
printf("60-80\t\t%d\t%d\t%d\t%d\n",t3,t7,t11,t15);
printf("low60\t\t%d\t%d\t%d\t%d\n",t4,t8,t12,t16);
}
void ave1(void)
{int n;
for(n=1;n<41;n++)
{temp=student[n].english+student[n].math+student[n].language-C+student[n].line-math;
student[n].average=temp/4.0;
}
for(n=1;n<41;n++)
printf("%f\n",student[n].average);
}
void ord(void)
{int n,i;
int student[n].t=1;
for(n=1;n<41;n++)
{for(i=1;i<41;i++)
{if(n==i)
continue;
else if(student[n].average<student[i].average)
student[n].t+=1;
}
}
for(n=1;n<41;n++)
printf("%d",student[n].t)
}
void student_seek(void)
{int n;
page_title("seek score\n");
if(n=check_number()!=-1)
printf("number\tname\tenglish\tmath\tclanguage\tlinemath\taverage\torder\n");
printf("%d\t%s\t%d\t%d\t%d\t%d\t%f\t%d\n",student[n].number,student[n].nam,student[n].english,student[n].math,student[n].clanguage,student[n].linemath,student[n].average,student[n].t);
}
void ave2(void)
{int n,a,b,c,d;
int temp1=0;
int temp2=0;
int temp3=0;
int temp4=0;
int temp5=0;
for(n=1;n<41;n++)
{temp1+=student[n].english;
temp2+=student[n].math;
temp3+=student[n].clanguage;
temp4+=student[n].linemath;
temp5+=student[n].average;
}
a=temp1/40.0;
b=temp2/40.0;
c=temp3/40.0;
d=temp4/40.0;
e=temp5/40.0;
printf("\t\t\t%f\t%f\t%f\t%f\t%f\n",a,b,c,d,e);
}
void browser(void)
{int n;
printf("number\tname\tenglish\tmath\tclanguage\tlinemath\taverage\torder\n");
for(n=1;n<41;n++)
{printf("%d\t%s\t%d\t%d\t%d\t%d\t%f\t%d\n",student[n].number,student[n].nam,student[n].english,student[n].math,student[n].clanguage,student[n].linemath,student[n].average,student[n].t);
}
printf("every subject's average");
ave();
sum();
}
main()
{menu:page_title("choice");
printf("use number keys to choice\n");
printf("1 print in students' new\n");
printf("2 change students' new\n");
printf("3 print in scores\n");
printf("4 change scoers\n");
printf("5 delete student's new");
printf("6 increase student's new");
printf("7 seek student's new");
printf("8 read\n");
printf("0 out\n");
switch(getch())
{case '1': student_new();break;
case '2': student_edit();break;
case '3': score_print();break;
case '4': score_edit();break;
case '5': student_del();break;
case '6': student_inc();break;
case '7': student_seek();break;
case '8': browser();break;
case '0': exit(0);
}
goto meun;
}
补充:

编写一个学生成绩管理的程序。由键盘输入数据(最好要考虑输入数据输入的格式及输入数据的有效性),然后进行以下的功能实现。程序要求主函数是一个功能选择菜单,其它各功能都用各自的函数实现。

要求至少有20个学生的原始数据。原始数据如下:

学号 姓名 C程序设计 高等数学 英语 线性代数

1 王.. 80 80 80 80

2 张.. 90 90 90 90

功能要求如下:

1、数据的输入

2、计算每位同学的平均分

3、计算每门课程的平均分

4、计算各分数段(90-100、80-89、60-79、60以下)的人数

5、对这10位同学的成绩按平均分排序,给出名次。

6、对数据可以进行增、删、改的编辑操作。

7、对数据可进行查询操作。

8、最后输出结果如下:

学号 姓名 C程序设计 高等数学 英语 线性代数 平均分 名次

1 王.. 80 80 80 80 80 2

2 张.. 90 90 90 90 90 1

各科平均分 85 85 85 85 85

90-100 1 1 1 1 1

80-89 1 1 1 1 1

60-69 0 0 0 0 0

60以下 0 0 0 0 0

追问:能找到的我都改了~就是因为找不到才问的~还剩下45个错误~就是不知道再哪错的

答案:好了。在VC里面编译可以通过了!

我不得不批评你一下:由于你的代码缺少注释,我不想去弄明白你的程序思路,对于大多数程序员,对没有注释的代码都很讨厌,我的代码里面注释占1/3,你的代码一点注释也没有,我想你的代码只是写给自己看的吧,呵呵,所以我修改你的代码时也没有在你的代码里面写注释,你就会明白不写注释有多么糟糕了。

我只帮你修正编译错误,能否按你的期望运行需要你自己去调试了。

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct STUDENT
{
int number,english,clanguage,math,linemath,average,t;
char name[20];
}student[41];

//定义page_title函数
void page_title(char *s)
{
printf("%s\n", s);
}

void student_new(void)
{
int n;

page_title("print in student's new:");
for(n=1;n<41;n++)
{
printf("number:");
scanf("%d",&student[n].number);
printf("name:");
scanf("%s",&student[n].name);
}
}

int check_number(void)
{
int n,i;
printf("print in student's number:");
scanf("%d",&i);
for(n=1;n<41;n++)
{
if(student[n].number==i)
{
printf("number:\n",student[n].number);
printf("name:\n",student[n].name);
return n;
}
}
printf("\nprint in wrong or no this number\n");
return -1;
}

void student_edit(void)
{
int n;
page_title("change student's new");
if(n=check_number()!=-1)
{
printf("\nprint in new informatian:\n");
printf("number:");
scanf("%d",&student[n].number);
printf("name:");
scanf("%s",&student[n].name);
}

/*/***************************************************
//原来的代码
}


printf("\nprint in wrong or no this number\n");
return -1;
}//错误括号,对应的括号哪里去了?

*************************************************/
/*******修改后*****/
}


void score_print(void)
{
int n,a,s;
page_title("print in score");
printf("\nuse the number keys to choice the subjict");
printf("\n1 english\n2 math\n3 clanguage\n4 linemath\n");
scanf("%d",&a);
for(n=1;n<41;n++)
{
printf("number:%d name:%s score:",student[n].number,student[n].name);
scanf("%d",&s);
switch(a)
{
case 1: student[n].english=s;break;
case 2: student[n].math=s;break;
case 3: student[n].clanguage=s;break;
case 4: student[n].linemath=s;break;
}
}

} //这里多一个括号你准备做什么用?

void score_edit(void)
{
int n;
page_title("change score");
if(n=check_number()!=-1)
{
printf("english:%d math:%d clangudge:%d linemath:%d",
// student[n].english,student[n].math,student[n].language-C,student[n].line-math); 原来的代码
//修改后:
student[n].english,student[n].math,student[n].clanguage,student[n].linemath);
printf("\nprint in score again:\n");
printf("english:");
scanf("%d",&student[n].english);
printf("math:");
scanf("%d",&student[n].math);
printf("language-C:");
scanf("%d",&student[n].clanguage);
printf("line-math:");
scanf("%d",&student[n].linemath);
}
}

void student_del(void)
{
int n;
page_title("delete student's new");
if(n=check_number()!=-1)
student[n].number=0;
printf("\nthe student has been deleted\n");
}

/***********
} //这里又多了一个括号。你使用括号非常糟糕!
***************************************/


void student_inc(void)
{
int n;
page_title("increase student's new");
if(n=check_number()==-1)
student[n].number+=1;
printf("\nthe student has been increased");
}

void sum(void)
{
int n;
int t1=0;
int t2=0;
int t3=0;
int t4=0;
int t5=0;
int t6=0;
int t7=0;int t8=0;
int t9=0;int t10=0;
int t11=0;int t12=0;
int t13=0;int t14=0;
int t15=0;int t16=0;
for(n=1;n<41;n++)
{
// if(studnet[n].english>=90 && student[n].english<=100) 原来的代码
if(student[n].english>=90 && student[n].english<=100)
t1+=1;
else if(student[n].english>=80 && student[n].english<90)
t2+=1;
/***
else if(student[n].english>=60 && studeng[n].english<80)****/
else if(student[n].english>=60 && student[n].english<80)

t3+=1;
else
t4+=1;

// if(studnet[n].math>=90 && student[n].math<=100)
//下面还有很多student的编写错误就不一一提示了。
if(student[n].math>=90 && student[n].math<=100)
t5+=1;
else if(student[n].math>=80 && student[n].math<90)
t6+=1;
else if(student[n].math>=60 && student[n].math<80)
t7+=1;
else
t8+=1;

if(student[n].clanguage>=90 && student[n].clanguage<=100)
t9+=1;
else if(student[n].clanguage>=80 && student[n].clanguage<90)
t10+=1;
else if(student[n].clanguage>=60 && student[n].clanguage<80)
t11+=1;
else
t12+=1;
if(student[n].linemath>=90 && student[n].linemath<=100)
t13+=1;
else if(student[n].linemath>=80 && student[n].linemath<90)
t14+=1;
else if(student[n].linemath>=60 && student[n].linemath<80)
t15+=1;
else
t16+=1;
}
printf("90-100\t\t%d\t%d\t%d\t%d\n",t1,t5,t9,t13);
printf("80-90\t\t%d\t%d\t%d\t%d\n",t2,t6,t10,t14);
printf("60-80\t\t%d\t%d\t%d\t%d\n",t3,t7,t11,t15);
printf("low60\t\t%d\t%d\t%d\t%d\n",t4,t8,t12,t16);
}

void ave1(void)
{
int n, temp; //增加定义temp变量
for(n=1;n<41;n++)
{
// temp=student[n].english+student[n].math+student[n].language-C+student[n].line-math;
temp=student[n].english+student[n].math+student[n].clanguage+student[n].linemath;
// student[n].average=temp/4.0;
student[n].average=temp/4;

}
for(n=1;n<41;n++)
printf("%f\n",student[n].average);
}

void ord(void)
{
int n,i;
// int student[n].t=1;
student[6].t = 1;
for(n=1;n<41;n++)
{
for(i=1;i<41;i++)
{
if(n==i)
continue;
else if(student[n].average<student[i].average)
student[n].t+=1;
}
}
for(n=1;n<41;n++)
// printf("%d",student[n].t)
printf("%d",student[n].t);
}

void student_seek(void)
{
int n;
page_title("seek score\n");

if(n=check_number()!=-1)
printf("number\tname\tenglish\tmath\tclanguage\tlinemath\taverage\torder\n");
// printf("%d\t%s\t%d\t%d\t%d\t%d\t%f\t%d\n",student[n].number,student[n].nam,student[n].english,student[n].math,student[n].clanguage,student[n].linemath,student[n].average,student[n].t);
printf("%d\t%s\t%d\t%d\t%d\t%d\t%f\t%d\n",
student[n].number,student[n].name,student[n].english,student[n].math,student[n].clanguage,student[n].linemath,student[n].average,student[n].t);
}

void ave2(void)
{
//int n,a,b,c,d;
int n,a,b,c,d,e;
int temp1=0;
int temp2=0;
int temp3=0;
int temp4=0;
int temp5=0;

for(n=1;n<41;n++)
{
temp1+=student[n].english;
temp2+=student[n].math;
temp3+=student[n].clanguage;
temp4+=student[n].linemath;
temp5+=student[n].average;
}
/*
a=temp1/40.0;
b=temp2/40.0;
c=temp3/40.0;
d=temp4/40.0;
e=temp5/40.0;
*/
//修改后:
a=temp1/40;
b=temp2/40;
c=temp3/40;
d=temp4/40;
e=temp5/40;

printf("\t\t\t%f\t%f\t%f\t%f\t%f\n",a,b,c,d,e);
}

void browser(void)
{
int n;
printf("number\tname\tenglish\tmath\tclanguage\tlinemath\taverage\torder\n");
for(n=1;n<41;n++)
{
//printf("%d\t%s\t%d\t%d\t%d\t%d\t%f\t%d\n",student[n].number,student[n].nam,student[n].english,student[n].math,student[n].clanguage,student[n].linemath,student[n].average,student[n].t);
printf("%d\t%

上一个:求C语言程序
下一个:什么叫做C语言和E语言?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,