| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 735 人关注过本帖
标题:我的程序出了错误
只看楼主 加入收藏
wanjiang
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2008-10-25
结帖率:100%
收藏
 问题点数:0 回复次数:8 
我的程序出了错误
不知道如何才能改正确。
代码:
#include <stdio.h>
#define N 5
struct student
{int num;
char name[20];
float score[4];
}stu[N];
struct student *fuc(struct student *);
main()
{struct student *ps;
int i,j;
for(i=0;i<5;i++)
{scanf("%d",&stu[i].num);
gets(stu[i].name);
for(j=0;j<4;j++)
scanf("%f",&stu[i].score[j]);
}
ps=fuc(stu);
printf("num:%d ,name:%s ,score0:%f ,score1:%f ,
       score2:%f ,score3:%f",ps->num,ps->name,ps->score[0],
       ps->score[1],ps->score[2],ps->score[3]);
}
struct student *fuc(struct student *pt)
{int i,j,imax;
float max,sum;
max=0.0;
for(i=0;i<N;i++)
{sum=0.0;
for(j=0;j<4;j++)
sum+=pt[i].score[j];
if(sum>max)
{max=sum;imax=i;}
return(&stu[imax]);
}}
搜索更多相关主题的帖子: 如何 include 
2008-10-28 16:52
zxwangyun
Rank: 4
来 自:云南
等 级:业余侠客
威 望:1
帖 子:232
专家分:299
注 册:2008-10-17
收藏
得分:0 
你的这函数调用,实在是看不懂,你干脆说下你想干啥吧
2008-10-28 18:39
fantasy_______
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2008-9-21
收藏
得分:0 
#include <stdio.h>
#define N 5
struct student
{int num;
char name[20];
float score[4];
}stu[N];
struct student *fuc(struct student *);
main()
{struct student *ps;
int i,j;
for(i=0;i<5;i++)
{scanf("%d",&stu[i].num);
gets(stu[i].name);
for(j=0;j<4;j++)
scanf("%f",&stu[i].score[j]);
}
ps=fuc(stu);
printf("num:%d ,name:%s ,score0:%f ,score1:%f ,score2:%f ,score3:%f"
       ,ps->num,ps->name,ps->score[0],ps->score[1],ps->score[2],ps->score[3]);
}
struct student *fuc(struct student *pt)
{int i,j,imax;
float max,sum;
max=0.0;
for(i=0;i<N;i++)
{sum=0.0;
for(j=0;j<4;j++)
sum+=pt[i].score[j];
if(sum>max)
{max=sum;imax=i;}
return(&stu[imax]);
}}
2008-10-28 18:51
wanjiang
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2008-10-25
收藏
得分:0 
楼上的兄弟厉害啊,我想了半天都没有想出怎么样才能把这个程序该对,现在可以。十分感谢。
2008-10-29 11:28
fantasy_______
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2008-9-21
收藏
得分:0 
回复 4# 的帖子
代码没改,格式改了,你写的不规范,再仔细看下把
2008-10-29 11:45
wanjiang
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2008-10-25
收藏
得分:0 
是的啊,把那个printf("num:%d ,name:%s ,score0:%f ,score1:%f ,score2:%f ,score3:%f"
       ,ps->num,ps->name,ps->score[0],ps->score[1],ps->score[2],ps->score[3]);
}
写规范,怎么那些问题就没有了呢?很疑问???
2008-10-29 15:13
dsr_dbh
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2008-10-29
收藏
得分:0 
也可以这样写。。
printf("num:%d ,name:%s ,score0:%f ,score1:%f ,"
       "score2:%f ,score3:%f",ps->num,ps->name,ps->score[0],
       ps->score[1],ps->score[2],ps->score[3]);
2008-10-30 09:24
wanjiang
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2008-10-25
收藏
得分:0 
想不到格式这么重要啊。我这个程序就是想统计五个人的四门考试成绩,总分最高的那个人的成绩。
2008-10-30 17:23
wanjiang
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2008-10-25
收藏
得分:0 
统计五个人的四门考试成绩,总分最高的那个人的成绩。
我上面的程序编的时候出了些问题,反复实践发现不能选出总分最高的那个,只能输出第一个人的信息。
程序代码:
#include <stdio.h>
#define N 5
struct student
{int num;
char name[20];
float score[4];
}stu[N];
struct student *fuc(struct student *);
main()
{struct student *ps;
int i,j;
for(i=0;i<5;i++)
{scanf("%d",&stu[i].num);
gets(stu[i].name);
for(j=0;j<4;j++)
scanf("%f",&stu[i].score[j]);
}
ps=fuc(stu);
printf("num:%d ,name:%s ,\nscore0:%f ,score1:%f ,score2:%f ,score3:%f"
       ,ps->num,ps->name,ps->score[0],
       ps->score[1],ps->score[2],ps->score[3]);
printf("\n");return 0;}
struct student *fuc(struct student *pt)
{int i,j,imax;
float max,sum;
max=0.0;
for(i=0;i<N;i++)
{sum=0.0;
for(j=0;j<4;j++)
sum+=pt[i].score[j];
if(sum>max)
{max=sum;imax=i;}
}return(&stu[imax]);
}

2008-10-31 15:52
快速回复:我的程序出了错误
数据加载中...
 
   



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

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