| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1101 人关注过本帖
标题:大家帮帮忙,看看程序为啥报错
只看楼主 加入收藏
echbsyljb
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2016-7-28
收藏
 问题点数:0 回复次数:2 
大家帮帮忙,看看程序为啥报错
程序如下:
#include<stdio.h>
#define N 3
struct Student
    {
        int num;
        char name[20];
        float score[3];
        float aver;
    };
   
   
int main()
{
    void input(struct Student stu[]);
    struct Student max(struct Student stu[]);
    void print(struct Student stud);
    struct Student stu[N],*p=stu,*q;
    input(p);
    q = &(max(p));
    print(*q);
   
    return 0;   
   
   
}

void input(struct Student stu[])
{
    int i;
    printf("请输入各学生的信息:学号、姓名、3门课程成绩:\n");
    for (i=0;i<N;i++)
        {
            scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].score[0],
            &stu[i].score[1],&stu[i].score[2]);
            stu[i].aver = (stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;
        }
}


struct Student max(struct Student stu[])
{
    int i,m=0;
    for(i=0;i<N;i++)
        {
            if (stu[i].aver>stu[m].aver)
                {
                    m = i;
                }
            }   
    return (stu[m]);
   
}

void print(struct Student stud)
{
    printf("\n成绩最高的学生是:\n");
    printf("学号:%d\n姓名:%s\n三门课成绩:%5.1f,%5.1f,%5.1f\n平均成绩:%6.2f\n",
            stud.num,stud.name,stud.score[0],stud.score[1],stud.score[2],stud.aver);
}

以上程序的第19行报错,[Error] lvalue required as unary '&' operand
不知道是什么问题,请朋友们帮忙看看
搜索更多相关主题的帖子: stu score void struct Student 
2020-09-02 13:57
jsonchang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2020-9-2
收藏
得分:0 
#include<stdio.h>
#define _CRT_SECURE_NO_WARNINGS
#define N 3
struct Student
{
    int num;
    char name[20];
    float score[3];
    float aver;
};


int main()
{
    void input(struct Student stu[]);
    struct Student max(struct Student stu[]);
    void print(struct Student stud);
    struct Student stu[N], * p = stu, * q,d;
    input(p);
    d = max(p);
    q =&d;
    print(*q);

    return 0;


}

void input(struct Student stu[])
{
    int i;
    printf("请输入各学生的信息:学号、姓名、3门课程成绩:\n");
    for (i = 0; i < N; i++)
    {
        scanf("%d %s %f %f %f", &stu[i].num, stu[i].name, &stu[i].score[0],
            &stu[i].score[1], &stu[i].score[2]);
        stu[i].aver = (stu[i].score[0] + stu[i].score[1] + stu[i].score[2]) / 3.0;
    }
}


struct Student max(struct Student stu[])
{
    int i, m = 0;
    for (i = 0; i < N; i++)
    {
        if (stu[i].aver > stu[m].aver)
        {
            m = i;
        }
    }
    return (stu[m]);

}

void print(struct Student stud)
{
    printf("\n成绩最高的学生是:\n");
    printf("学号:%d\n姓名:%s\n三门课成绩:%5.1f,%5.1f,%5.1f\n平均成绩:%6.2f\n",
        stud.num, stud.name, stud.score[0], stud.score[1], stud.score[2], stud.aver);
}
具体可以看下https://blog.
2020-09-02 17:59
echbsyljb
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2016-7-28
收藏
得分:0 
回复 2楼 jsonchang
谢谢,我看了,写的挺有道理的。
2020-09-02 19:53
快速回复:大家帮帮忙,看看程序为啥报错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017887 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved