标题:小白求助,球求大佬帮个忙,帮忙查个错
取消只看楼主
西瓜瓤
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2022-5-28
结帖率:14.29%
已结贴  问题点数:10 回复次数:6 
小白求助,球求大佬帮个忙,帮忙查个错
#include "stdio.h"
#include "stdlib.h"
struct courses
{
    int programming;
    int database;
    int network;
    double score;
    int level;
    scanf("%lf",&score);
        if (score>300||score<0) //300分如何计算及格分来评定等级               还有这个if结构不知道哪里错了
         {
           printf("成绩输入错误!\n");
         }
    else
        {
          level=(int)((score-180)/10);
          switch(level)
                {
                 case 1: printf("优\n");break;
                 case 2: printf("优\n");break;
                 case 3: printf("良\n");break;
                 case 4: printf("中\n");break;
                 case 5: printf("差\n");break;
                 default: printf("劣\n");break;
                }
        }
};
struct student
{
    int num;       //学号
    char name[10]; //姓名
    int sum;       //总分
    struct courses sc[3];
};
void sumScore(struct student students[])
{
    int i;
    for (i = 0; i < 3; i++)
       {
         students[i].sum=students[i].sc[0].programming+students[i].sc[1].network+students[i].sc[2].database;
       }
}
int main()
{
    struct student students[5];//3名同学
    int i;
    for (i = 0; i < 3; i++)
       {
            printf("num:");
            scanf("%d",&students[i].num);
            printf("name:");
            scanf("%s",students[i].name);
            printf("programming score:");
            scanf("%d",&students[i].sc[0].programming);
            printf("network score:");
            scanf("%d",&students[i].sc[1].network);
            printf("database score:");
            scanf("%d",&students[i].sc[2].database);
        }
    sumScore(students);
    printf("num\tname\tsum\n");
    for (i = 0; i < 3; i++)
       {
        printf("%d\t%s\t%d\n",students[i].num,students[i].name,students[i].sum);
       }
      
    return 0;
}
搜索更多相关主题的帖子: int break scanf printf score 
2022-05-29 11:21
西瓜瓤
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2022-5-28
得分:0 
回复 2楼 wp231957
谢谢,那300分做为总分应该怎么做等级评定呢
2022-05-29 12:28
西瓜瓤
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2022-5-28
得分:0 
回复 2楼 wp231957
我改了,但是想满足3名学生的他三科总分以及评定就比如100分
printf("请输入成绩:\n");
      scanf("%lf",&score);
    if (score>100||score<0){
        printf("成绩输入错误!\n");
}
    else
    {
        level=(int)((score-50)/10);
        switch(level)
        {
        case 5: printf("优\n");break;
        case 4: printf("优\n");break;
        case 3: printf("良\n");break;
        case 2: printf("中\n");break;
        case 1: printf("差\n");break;
        default: printf("劣\n");break;
        }
     }
那300分呢
2022-05-29 12:37
西瓜瓤
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2022-5-28
得分:0 
回复 6楼 wp231957
数学不太好,这串代码是要满足该咋写:level=(int)((score-50)/10);//就是该除多少才能满足
2022-05-29 12:51
西瓜瓤
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2022-5-28
得分:0 
回复 8楼 wp231957
改完了,还有一个问题就是我需要入三名同学三科总成绩以及评等级但是我这么写只能一名同学成绩
2022-05-29 13:08
西瓜瓤
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2022-5-28
得分:0 
回复 10楼 wp231957
啥意思
2022-05-29 13:14
西瓜瓤
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2022-5-28
得分:0 
回复 10楼 wp231957
就是我已经这样了但是不能满足三人只能输出一人
#include "stdio.h"
#include "stdlib.h"
struct courses
{
    int programming;
    int database;
    int network;
    double score;
   
};
struct student
{
    int num;       //学号
    char name[10]; //姓名
    int sum;       //总分
    struct courses sc[3];
};
void sumScore(struct student students[])
{
    int i;
    for (i = 0; i < 3; i++)
       {
         students[i].sum=students[i].sc[0].programming+students[i].sc[1].network+students[i].sc[2].database;
       }
}
int main()
{
    struct student students[5];//3名同学
       double score;
       int level;
       int i;
    for (i = 0; i < 3; i++)
       {
            printf("num:");
            scanf("%d",&students[i].num);
            printf("name:");
            scanf("%s",students[i].name);
            printf("programming score:");
            scanf("%d",&students[i].sc[0].programming);
            printf("network score:");
            scanf("%d",&students[i].sc[1].network);
            printf("database score:");
            scanf("%d",&students[i].sc[2].database);
        }
    sumScore(students);
    printf("num\tname\tsum\n");
    for (i = 0; i < 3; i++)
       {
        printf("%d\t%s\t%d\n",students[i].num,students[i].name,students[i].sum);
       }
      
       scanf("%lf",&score);
        if (score>300||score<0)
         {
           printf("成绩输入错误!\n");
         }
        else
            {
             level=(int)(score/50);
             switch(level)
                   {
                    case 5: printf("优\n");break;
                    case 4: printf("优\n");break;
                    case 3: printf("良\n");break;
                    case 2: printf("中\n");break;
                    case 1: printf("差\n");break;
                    default: printf("劣\n");break;
                   }
            }
    return 0;
}
名字学号总分都可以输出就是等级不行

2022-05-29 13:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-509203-1-1.html




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

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