| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 999 人关注过本帖
标题:求大神,一个结构体问题
只看楼主 加入收藏
jioper
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2016-10-21
结帖率:70%
收藏
 问题点数:0 回复次数:6 
求大神,一个结构体问题
题目是要求输入学生学号,三门课成绩,计算总分并且按表格方式输出该表,加粗行有错,但我不知道为什么?求解答
我的程序如下
#include"stdio.h"
void main()
{
    int i,j;
    struct student
    {
     char name[5];
     double score[3];
     int studentnumber;
     double total;
    }stu[5];
    printf("请输入5个学生的学号,3门科成绩:\n");
    for(i=0;i<5;i++)
    {
        int total=0;
        scanf("%s",stu[i].name);
        scanf("%d",&stu[i].studentnumber);
        for(j=0;j<3;j++)
        {
            scanf("%lf",&stu[i].score[j]);
            stu[i].total=stu[i].total+stu[i].score;//error: pointer addition requires integral operand
        }
    }
        for(i=0;i<5;i++)
        {
        printf("%s\t%d\t%d\t%d\t",stu[i].name,stu[i].score,stu[i].studentnumber,stu[i].total);
        }
}


[此贴子已经被作者于2016-12-3 19:40编辑过]

搜索更多相关主题的帖子: include double 结构体 
2016-12-03 18:58
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:0 
stu[i].total=stu[i].total+stu[i].score[b];//b是从哪里来的?不是i么???
还有,声明结构体数组不是struct student stu[5];么,直接声明 student stu[5];能行得通么?

[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2016-12-03 19:12
jioper
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2016-10-21
收藏
得分:0 
回复 2楼 九转星河
那个【b】好像是这个论坛的加粗符号,我本身没写,那个声明我改了,可还是存在我原文说的错误
2016-12-03 19:39
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:0 
double score[3];//你自己设计了三科成绩,score是一个数组,你得指明数组元素啊~
//stu[i].total=stu[i].total+stu[i].score[j];//score[j];是吧?

//还有,细节要你自己慢慢改~

[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2016-12-03 20:02
jioper
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2016-10-21
收藏
得分:0 
回复 4楼 九转星河
好,谢谢
2016-12-03 20:23
炎天
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:桃花岛
等 级:贵宾
威 望:29
帖 子:1218
专家分:4986
注 册:2016-9-15
收藏
得分:0 
#include"stdio.h"
 main()
 {
     int i, j;
     struct student
     {
       char name[5];
       double score[3];
       int studentnumber;
       double total;
     }stu[5];
     
     printf("请输入5个学生的学号,3门科成绩:\n");
     for(i = 0; i < 5; i++)
     {
         stu[i].total = 0;
         scanf("%s", stu[i].name);
         scanf("%d", &stu[i].studentnumber);
         for(j = 0; j < 3; j++)
         {
             scanf("%lf", &stu[i].score[j]);
             stu[i].total = stu[i].total + stu[i].score[j];//error: pointer addition requires integral operand
         }
     }
     
     for(i = 0; i < 5; i++)
     {
        printf("\n%s\t  %.2lf\t  %.2lf\t  %.2lf\t  %d\t  %.2lf\t",stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].studentnumber,stu[i].total);
     }
 }

早知做人那么辛苦!  当初不应该下凡
2016-12-03 20:39
jioper
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2016-10-21
收藏
得分:0 
回复 6楼 炎天
多谢,非常清楚了
2016-12-03 21:01
快速回复:求大神,一个结构体问题
数据加载中...
 
   



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

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