c语言程序纠错

#include <stdio.h>
int main()
{
int score[3];
int i,x,temp;
for(i=0;i<4;i++);
{
Receive data:scanf("%d",&temp);
if(temp>120) printf("%d请输入正确分数\n",temp) goto Receive data;
score[i]+temp
}
x=score[1]+score[2]+score[3];
if(x<220) printf("%d此学生分数太低请重新输入\n",x)
if(score[1]<score[2]) if(score[2]<score[3]) printf("%d此学生英语最好",score[3]);
else if(score[2]>score[3]) printf("%d此学生数学最好",score[2]);
if(score[1]>score[2]) if(score[1]>score[3]) printf("%d此学生语文最好",score[1]);
else if(score[1]<score[3]) printf("%d此学生英语最好",score[3]);
if(score[1]=score[2]) if(score[1]>score[3]) printf("%d此学生语文最好",score[1]);
else if(score[1]<score[3]) printf("%d此学生英语最好",score[3]);
getch();
}

首先要注意格式。。

    goto语句设置的label设置有问题,中间不能有空格

    for循环写完for(;;)后 不要加 ;

    第一个for语句想要循环3次却循环了4次

    score[i]+temp应该是想要将temp的值给score[i]吧。。

    if内的语句如果超过了一句,那么就要用 {   } 把if里的语句括起来,下面会有例子

    漏了一些分号,把一些;打成了中文的;

    getchar(),不是getchar()

    判断两个相等需要用 ==  而不是=

    goto最好少用 或者不用

    数组只有在定义的时候是告诉计算机有多少个,而在使用单个元素时:

    比如说 定义一个整形数组a,有3个元素 int a[3];其中每个元素是a[0],a[1],a[2],而不是a[1],a[2],a[3]

    使用int main()时,在程序最后要加上return 0;


下面是修改后的程序,如果对你有帮助,望采纳( ”//“之后为注释)

#include <stdio.h>
int main()
{
    int score[3];
    int i,x,temp;
    for(i=0;i<3;i++)//让循环进行3次
    {
Receive_data://用下划线连起来
scanf("%d",&temp);
if(temp>120)//if内超过一句需要用大括号({})括起来
{
    printf("请输入正确分数\n");//不要忘记分号
    goto Receive_data;
}
score[i]=temp;//赋值方式
    }
    x=score[0]+score[1]+score[2];//数组内元素的使用方式
    if(x<220) 
    {
printf("此学生分数太低请重新输入\n");
i=0;
goto Receive_data;
    }
    if(score[0]<score[1]) 
    {
if(score[1]<score[2])
    printf("%d此学生英语最好",score[2]);
        else if(score[1]>score[2])
    printf("%d此学生数学最好",score[1]);
    }
    if(score[0]>score[1])
    {
        if(score[0]>score[2]) 
            printf("%d此学生语文最好",score[0]);
        else if(score[0]<score[2]) 
    printf("%d此学生英语最好",score[2]);//分号必须是英文的
    }
    if(score[0]==score[1]) 
    {
if(score[0]>score[2])
    printf("%d此学生语文最好",score[0]);
        else if(score[0]<score[2]) 
    printf("%d此学生英语最好",score[2]);
    }
    getchar();//getchar()
    return 0;//int main()要返回一个值 return 0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-09-30
score[i]+temp ------------> score[i]+=temp;
相似回答