| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1015 人关注过本帖
标题:求指正错误,结构体
只看楼主 加入收藏
Aglrialee
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2016-11-20
结帖率:100%
收藏
已结贴  问题点数:5 回复次数:9 
求指正错误,结构体
#include<stdio.h>
struct Student
{
    char ID[10];
    char name[20];
    double score;
};
typedef struct Student st;
void input(struct Student *pa,int n)
{
    int i;
    for(i=0;i<n;i++)
    {  
    scanf("%d%s%f",&pa[i].ID,pa[i].name,&pa[i].score);
    }
}
void max(struct Student*pa,int n)
{
int i,max;
char a[10],b[20];
max=pa[1].score;
a[10]=pa[1].ID;
b[20]=pa[1].name;
for(i=0;i<n;i++)
if(pa[i].score>max)
{
max=pa[i].score;
a[10]=pa[i].ID;
b[20]=pa[i].name;
}
printf("The student who has the highest score is:%s%s%d",a[10],b[20],max);
}
编译没有错误,但运行一直出错
int main()
{
    struct Student st[10];
    int x,i;
    double ave;
    do
    {
        scanf("%d",&x);
    }while(x<=0||x>=10);
    input(st,x);
    for(i=0;i<x;i++)
       ave+=st[1+i].score;
    printf("The average score=%.2f\n",ave);
    max(st,x);
    return 0;
   
}
搜索更多相关主题的帖子: include double 结构体 
2016-12-28 20:53
倾听心跳
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:153
注 册:2016-6-22
收藏
得分:0 
程序代码:
#include<stdio.h>
struct Student
{
    char ID[10];
    char name[20];
    double score;
};
typedef struct Student st;
void input(struct Student *pa,int n)
{
    int i;
    for(i=0;i<n;i++)
    {  
    scanf("%d%s%f",&pa[i].ID,pa[i].name,&pa[i].score);
    } 
}
void max(struct Student*pa,int n)
{
double max;
int i;
char a[10],b[20];
max=pa[1].score;
a[10]=*pa[1].ID;
b[20]=*pa[1].name;
for(i=0;i<n;i++)
if(pa[i].score>max)
{
max=pa[i].score;
a[10]=*pa[i].ID;
b[20]=*pa[i].name;
}
printf("The student who has the highest score is:%s%s%d",a[10],b[20],max);
}
int main()
{
    struct Student st[10]; 
    int x,i;
    double ave;
    do
    {
        scanf("%d",&x);
    }while(x<=0||x>=10);
    input(st,x);
    for(i=0;i<x;i++)
       ave+=st[1+i].score; 
    printf("The average score=%.2f\n",ave);
    max(st,x);
    return 0;
    
}
2016-12-28 21:11
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
是不是输入时出错  估计是没有分配空间的缘故

DO IT YOURSELF !
2016-12-28 21:12
倾听心跳
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:153
注 册:2016-6-22
收藏
得分:0 
指针有待加强
2016-12-28 21:12
Aglrialee
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2016-11-20
收藏
得分:0 
回复 2楼 倾听心跳
还是运行不了,求平均数那边有问题么
2016-12-28 21:18
倾听心跳
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:39
专家分:153
注 册:2016-6-22
收藏
得分:0 
你程序运行时没任何提示,不知怎么输入
2016-12-28 21:30
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:5 
勉强改好了~~~很多大大小小的问题~

程序代码:
#include<stdio.h>
#include<string.h>
struct Student
{
    char ID[10];
    char name[20];
    double score;
};
typedef struct Student st;
void input(struct Student pa[],int n)
{
    int i;
    for(i=0;i<n;i++)
    {  
        scanf("%s%s%lf",pa[i].ID,pa[i].name,&pa[i].score);
    } 
}
void max(struct Student*pa,int n)
{
    int i;
    double max;
    char a[10],b[20];
    max=pa[0].score;
    strcpy(a,pa[0].ID);
    strcpy(b,pa[0].name);

    for(i=0;i<n;i++)
        if(pa[i].score>max)
        {
             max=pa[i].score;
             strcpy(a,pa[i].ID);
             strcpy(b,pa[i].name);
        }
    printf("The student who has the highest score is:%s %s %.2f",a,b,max);
}

int main()
{
    struct Student st[10]; 
    int x,i;
    double ave=0;
    do
    {
        scanf("%d",&x);
    }while(x<=0||x>=10);
    input(st,x);
    for(i=0;i<x;i++)
       ave+=st[i].score; 

    printf("The average score=%.2f\n",ave);

   max(st,x);

    return 0;
    
}

[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2016-12-28 21:32
Aglrialee
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2016-11-20
收藏
得分:0 
回复 7楼 九转星河
谢谢谢谢,真的零零碎碎的错误一堆,麻烦了。但还是有一个小问题,就是最后输出的成绩最高的那个人的学号变成了一个小方框,请问是什么原因呀
2016-12-28 21:46
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:0 
我也不好说~看看你的输入格式~~~

[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2016-12-28 21:48
Aglrialee
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2016-11-20
收藏
得分:0 
回复 9楼 九转星河
啊,是输入格式有问题,真的太谢谢大神了,解决了
2016-12-28 21:53
快速回复:求指正错误,结构体
数据加载中...
 
   



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

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