| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1039 人关注过本帖
标题:曦瓜 15:26:55 就是想做一个录入3名同学的成绩的登记程序 ,然后等级评价这一 ...
取消只看楼主 加入收藏
西瓜瓤
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2022-5-28
结帖率:14.29%
收藏
已结贴  问题点数:10 回复次数:0 
曦瓜 15:26:55 就是想做一个录入3名同学的成绩的登记程序 ,然后等级评价这一块始终无法和班级姓名学号一样输出
#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;       //总分
    char sumlevel;
    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;
       }
}
void sumLevel(struct student students[])
{
   int i;
   char sumlevel;
   for (i = 0; i < 3; i++)
             {
             sumlevel=(int)( students[i].sum/50);
             }
         scanf("%lf",& students[i].sum);
         if ( students[i].sum>300|| students[i].sum<0)
            {
           printf("成绩输入错误!\n");
            }
        else
            {
             sumlevel=(int)( students[i].sum/50);
             switch(sumlevel)
                   {
                    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;
                   }
            }
}
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);
    sumLevel(students);
    printf("num\tname\tsum\n");
    for (i = 0; i < 3; i++)
       {
        printf("%d\t%s\t%d\t%s\n",students[i].num,students[i].name,students[i].sum,students[i].sumlevel);
       }
      
    return 0;
}
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: struct int printf scanf sum 
2022-05-29 16:56
快速回复:曦瓜 15:26:55 就是想做一个录入3名同学的成绩的登记程序 ,然后等级评 ...
数据加载中...
 
   



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

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