| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1161 人关注过本帖
标题:请问这个代码运行后总分为什么不对,哪里错了,怎样改?谢谢!
只看楼主 加入收藏
风雨同舟共济
Rank: 1
来 自:揭阳
等 级:新手上路
帖 子:10
专家分:0
注 册:2016-12-30
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
请问这个代码运行后总分为什么不对,哪里错了,怎样改?谢谢!
#include<stdio.h>
struct student{
int num;
char name;
int chinese,math,english,total;
};
void main()
{
int i,n;
struct student s[50],*p;
p=s;
void output_total(struct student *p,int n);
struct student input();
printf("输入学生的人数: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("输入第%d个学生的基本信息: \n",i);
s[i]=input();
output_total(s,n);
}
}
struct student input()
{
struct student s;
printf("学号 姓名 语文 数学 英语: \n");
scanf("%d%s%d%d%d",&s.num,&s.name,&s.chinese,&s.math,&s.english);
return s;
}
void output_total(struct student *p,int n)
{
(*p).total=(*p).chinese+(*p).math+(*p).english;
printf("总成绩为%d\n",(*p).total);
}


搜索更多相关主题的帖子: include english 英语 数学 信息 
2017-01-05 18:19
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10539
专家分:42927
注 册:2014-5-20
收藏
得分:10 
#include<stdio.h>

struct student
{
    int num;
    char name[10];
    int chinese,math,english,total;
};

void output_total(struct student *p);
void input(struct student *p);

void main()
{
    int i,n;
    struct student s[50];
    printf("输入学生的人数: ");
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        printf("输入第%d个学生的基本信息: \n",i);
        input(&s[i]);
        output_total(&s[i]);
    }
}

void input(struct student *p)
{
    printf("学号 姓名 语文 数学 英语: \n");
    scanf("%d%s%d%d%d",&p->num,p->name,&p->chinese,&p->math,&p->english);
}

void output_total(struct student *p)
{
    p->total = p->chinese + p->math + p->english;
    printf("总成绩为%d\n", p->total);
}
2017-01-05 21:04
bjut_Allen
Rank: 9Rank: 9Rank: 9
来 自:平乐园工业技术学校
等 级:蜘蛛侠
威 望:8
帖 子:323
专家分:1223
注 册:2016-10-16
收藏
得分:10 
output_total(&s[i]);

Code is my life.
2017-01-05 21:27
快速回复:请问这个代码运行后总分为什么不对,哪里错了,怎样改?谢谢!
数据加载中...
 
   



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

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