| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 872 人关注过本帖
标题:各位大佬,我实在看不懂怎么错,求助
只看楼主 加入收藏
阿朱Zzzz
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2019-5-13
收藏
 问题点数:0 回复次数:2 
各位大佬,我实在看不懂怎么错,求助
#include<stdio.h>
#define N 30
void Readscore(int id[],int score[],int n);/*录入每个学生的学号和考试成绩*/
int Average(int score[],int n);/*计算平均分*/
int a1(int score[],int n);/*计算总分*/
void Datasort1(int id[],int score[],int n);/*进行成绩排序*/
void  Datasort2(int id[],int score[],int n);/*进行学号排序*/
int Selectsort(int id[],int score[],int n,int x); /*按照学号查询排名以及考试成绩*/
void Scoreclass(int score[],int n);/*分出分数段*/
void Showinfo(int id[],int score[],int n); /*输出每个学生的学号和成绩*/
int main()
{
    int num,score[N],aver,n,SUM,id[N],i,m,k,great=0,better=0,middle=0,low=0,lower=0,x;
while(1){
//首页选择
    printf("----------------\n");
    printf("1.录入学生的学号和成绩\n");
    printf("2.学生课程的总分和平均分\n");
    printf("3.按分数降序排列\n");
    printf("4.按数字升序排序\n");
    printf("5.查询学号\n");
    printf("6.统计分析\n");
    printf("7.数据列表\n");
    printf("0.退出\n");
    printf("请进入你的选择\n");
    scanf("%d",&num);
//用户输入功能

    switch(num)
    {
        case 0:

            break;
        case 1:
            printf("输入人数 n:\n");
            scanf("%d",&n);
            Readscore(id,score,n);
            break;

        case 2:
            aver=Average(score,n),SUM=a1(score,n);
            printf("课程的总分为%d,平均分为%d\n",&SUM,&aver);
            break;
        case 3:
            Datasort1(id,score,n);
            for(i=0;i<=n-1;i++)
            {
                printf("%3d%5d\n",id[i],score[i]);/*输出成绩排序结果*/
            }
            break;
        case 4:
            Datasort2(id,score,n);
            for(i=0;i<=n-1;i++)
            {
                printf("%3d%5d\n",id[i],score[i]);/*输出学号和成绩*/
            }
            break;
        case 5:
            printf("Input id:\n");
            scanf("%d",&x);
            m=Selectsort(id,score,n,x);
            if(m==-1)
            {
                printf("查询错误\n");
            }else
            {
                printf("----------------\n");
                printf("id:%3d score:%3d 排名:%3d\n",id[m],score[m],m+1);
            }
            break;
        case 6:
            Scoreclass(score,n);
            break;
        case 7:
            Showinfo(id,score,n);
            sum=Average(score,n);
            printf("----------------\n");
            printf("Sum score is %d\n",sum);
            printf("Average score is %d\n",sum/n);
            break;
            
        default:
            printf("无效的操作符\n");

    }
        }
}

void Readscore(int id[],int score[],int n)/*通过函数记录学生的学号和成绩,当输入为负值时结束输入,并且返回学生人数*/
{
    int i;
    for(i=0;i<n;i++)
    {
        printf("输入学生的学号和成绩:");
        scanf("%d %d",&id[i],&score[i]);
        if(score[i]<0)
        {
            printf("成绩输入错误\n");
        }
    }
}
int Average(int score[],int n)
{
    int i,sum=0;
    for(i=0;i<n;i++)
    {
        sum+=score[i];
    }
    return n>0?sum/n:-1;
}
int a1(int score[],int n)
{
    int i,sum=0;
    for(i=0;i<n;i++)
    {
        sum+=score[i];
    }
    return sum;
}
void Datasort1(int id[],int score[],int n)
{
    int i,j,temp;
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(score[j]>score[i])
            {
                temp=score[j];
                score[j]=score[i];
                score[i]=temp;
            }
        }
    }
}

void Datasort2(int id[],int score[],int n)
{
    int temp_score,i,j,temp_id,k,x;
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(score[i]<score[j])
            {
                    temp_score = score[i];
                    score[i]=score[j];
                    score[j]=temp_score;
                    temp_id=id[i];
                    id[i]=id[j];
                    id[j]=temp_id;
            }
        }
    }
    for(k=0;k<n;k++)
    {
        if(id[k]==x)
        return k;
    }
    return -1;
}
int Selectsort(int id[],int score[],int n,int x)
{
    int temp_score,i,j,temp_id,k,x;
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(score[i]<score[j])
            {
                    temp_score = score[i];
                    score[i]=score[j];
                    score[j]=temp_score;
                    temp_id=id[i];
                    id[i]=id[j];
                    id[j]=temp_id;
            }
        }
    }
    for(k=0;k<n;k++)
    {
        if(id[k]==x)
            return k;

    }return -1;
}
void Scoreclass(int score[],int n)
{

    int i,j,count,k;
    double bate,m;
    m=n;
    int begin[5]={0,60,70,80,90};
    int end[5]={59,69,79,89,100};
    char* class[5]={"不及格","及格","中等","良好","优秀"};

    for(i=0,j=0;i<=n,j<5;i++,j++)
    {
            count =0;
            bate=0;
       for(k=0;k<n;k++)
       {
          if((begin[i]<=score[k])&&(end[i]>=score[k]))
          {
             count+=1;
             bate=(100*count)/m;
          }

       }

       printf("%s的学生人数为:%d ,所占百分比为%.2f\n",class[j],count,bate/100);

    }
}
void Showinfo(int id[],int score[],int n)
{
    int i;
    for(i=0;i<=n-1;i++)
    {
        printf("id:%3d score:%3d\n",id[i],score[i]);
    }
}
图片附件: 游客没有浏览图片的权限,请 登录注册

搜索更多相关主题的帖子: score int SUM printf for 
2019-05-13 23:39
阿朱Zzzz
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2019-5-13
收藏
得分:0 
关键是最开始的总分和平均数输出来是好几位的数字,那里就已经搞不懂为什么了
2019-05-13 23:43
阿朱Zzzz
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2019-5-13
收藏
得分:0 
case 7:
            Showinfo(id,score,n);
            aver=Average(score,n),SUM=a1(score,n);
            printf("----------------\n");
            printf("课程的总分为%d,平均分为%d\n",&SUM,&aver);
            break;

七改成这个
2019-05-13 23:46
快速回复:各位大佬,我实在看不懂怎么错,求助
数据加载中...
 
   



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

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