吃女巫的女孩 2023-12-10 17:16 采纳率: 100%
浏览 6
已结题

以下代码为什么会这样报错,该如何解决

img

img

img

img

img

img


以上代码在电脑Microsoft VisualC++2010运行,生成解决方案时为什么会出现如上图的报错,该如何解决
以下为题目

img

img

  • 写回答

3条回答 默认 最新

  • 关注

    把max函数换个名字就可以了,跟系统的max宏定义函数重名了。
    我敲了一遍代码,应该是只有这个问题。

    #include <stdio.h>
    #include <stdlib.h>
    #define NUM 3
    struct student
    {
        int num;
        char name[20] ;
        float eng;
        float math;
        float phil;
        float com;
        float elec;
        float total;
    }stu[NUM],p;
    void input (struct student stu[])
    {
        int i;
        for (i=0; i<NUM;i++)
        {
            scanf("%d %s %f %f %f %f %f", &stu[i].num, stu[i].name, &stu[i].eng, &stu[i].math, &stu[i].phil, &stu[i].com, &stu[i].elec) ;
            stu[i].total=stu[i].eng+stu[i].math+stu[i].phil+stu[i].com+stu[i].elec;
        }
    }
    void PrintScore (struct student stu[], float x[])
    {
        int i, j, q, n1=0, n2=0, n3=0, n4=0, n5=0;
        float sum=0, t1, t2, t3, t4, t5;
        struct student p;
        printf("学号       姓名       成绩\n");
        for (i=0; i<NUM;i++)
        {
            for (j=i+1;j<NUM;j++)
            {
                if (stu[i].num>stu[j].num)
                {
                    p=stu[i];
                    stu[i]=stu[j];
                    stu[j]=p;
                }
            }
        }
        for(i=0;i<NUM;i++)
        {
            printf("%d      %s      %.1f\n",stu[i].num,stu[i].name,x[i]);
            sum=sum+x[i];
            q=(int)x[i]/10;
            switch(q)
            {
            case 10:
            case 9:
                n1++;
                break;
            case 8:
                n2++;
                break;
            case 7:
                n3++;
                break;
            case 6:
                n4++;
                break;
            default:
                n5++;
                break;
    
            }
        }
        printf("全班成绩统计: \n");
        printf("平均分: %.1f\n", (float) sum/NUM) ;
        t1= (float) n1/NUM;
        t2= (float) n2/NUM;
        t3= (float) n3/NUM;
        t4= (float) n4/NUM;
        t5= (float) n5/NUM;
        printf("90^ 100分(优) : %d人  占%d%%\n",n1, (int) (t1*100)) ;
        printf("80^ 89分(良) : %d人  占%d%%\n",n2, (int) (t2*100));
        printf("70 ~79分(中) : %d人  占%d%%\n",n3, (int)(t3*100)) ;
        printf("60 ~69分(及格) : %d人  占%d%%\n",n4, (int) (t4*100)) ;
        printf("0 ~59分(不及格) : %d人  占%d%%\n",n5, (int) (t5*100)) ;
    
    }
    void maxScore (struct student stu[])
    {
        int i;
        struct student p ;
        for(i=1; i<NUM;i++)
        {
            if (stu[0].total<stu[i].total)
            {
                p=stu[i];
                stu[i]=stu[0];
                stu[0]=p;
            }
        }
    }
    
    
    
    
    int main()
    {
        FILE *pf;
        int i, j;
        float avg, eng[NUM], math[NUM], phil[NUM], com[NUM], elec[NUM];
        pf=fopen("cj.dat","w");
        if (pf==NULL)        
        {
            printf ("Cannot open fi1e. \n");
            exit(1);
        }
        input (stu) ;
        for (i=0; i<NUM;i++)
        {
            for (j=i+1;j<NUM;j++)
            {
                if (stu[i].total<stu[j].total)
                {
                    p=stu[i];
                    stu[i]=stu[j];
                    stu[j]=p;
                }
            }
        }
        for (i=0; i<NUM; i++)
        {
            fprintf (pf,"%d,%s,%.1f,%.1f,%.1f,%.1f,%.1f\n",stu[i].num, stu[i].name, stu[i].eng, stu[i].math, stu[i].phil, stu[i].com, stu[i].elec);
        }
        printf("课程名称:英语\n");
        for (i=0; i<NUM;i++)
        {
            eng[i]=stu[i].eng;
        }
        PrintScore (stu, eng) ;
        printf("课程名称:高数\n");
        for (i=0; i<NUM;i++)
        {
            math[i] =stu[i].math;
        }
        PrintScore (stu, math);
        printf("课程名称:马哲\n");
        for (i=0; i<NUM;i++)
        {
            phil[i]=stu[i].phil;
        }
        PrintScore (stu, phil);
        printf("课程名称:计算机\n");
        for (i=0; i<NUM;i++)
        {
            com[i]=stu[i].com;
        }
        PrintScore (stu, com) ;
        printf("课程名称:电子技术\n");
        for (i=0;1<NUM;i++)
        {
            elec[i]=stu[i].elec;
        }
        PrintScore (stu,elec) ;
        maxScore(stu) ; //这里修改了函数名
        avg= (stu[0].eng+stu[0].math+stu[0].phil +stu[0].com+stu[0].elec)/5.0;
        printf("总分最高的学生的学号,姓名,英语成绩,高数成绩,马哲成绩,计算机成绩,电子技术成绩,平均分数分别为: \n");
        printf("%d %s %.1f %.1f %.1f %.1f %.1f %.1f\n", stu[0].num, stu[0].name, stu[0].eng,stu[0].math, stu[0].phil, stu[0].com, stu[0].elec,avg);
        getchar();
        return 0;
    }
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 12月18日
  • 已采纳回答 12月10日
  • 创建了问题 12月10日