学C语言自己写的一个程序

这是自己学C语言时,突发奇想写一个计算一学期平均绩点的小程序,当时很兴奋,觉得有收藏价值。所以自己收藏一下!当然写得还是很一般。

 
 


 

 

#include <stdio.h>
void main()
{
 int i=0;
 int j=0;
 int test_lessons=0;
 int check_lessons=0;
 char check_level[5];
 float check_credit[20];
 float test_credit[20];
 float check_point[20];
 float test_point[20];
 float total1=0.00;
 float total2=0.00;
 float total_credit1=0.00;
 float total_credit2=0.00;
 float test_mark[5];
 printf("**********************************\n");
        printf("*       优秀等级对应输入A        *\n");
 printf("*       良等级对应输入B          *\n");
 printf("*       中等级对应输入C          *\n");
 printf("*       及格等级对应输入D        *\n");
 printf("*       不及格等级对应输入E      *\n");
 printf("**********************************\n");
    printf("请输入考查课的课数:");
 scanf("%d",&check_lessons);
 fflush(stdin);
    printf("请输入所有考查课的学分:");
 for(i=0;i<check_lessons;i++)
  scanf("%f",&check_credit[i]);
 fflush(stdin);
     printf("请输入所对应的考查课的等级:");
  for(i=0;i<check_lessons;i++)
  {scanf("%c",&check_level[i]);
  if(check_level[i]=='A'||check_level[i]=='B'||check_level[i]=='C'||check_level[i]=='D'||check_level[i]=='E')
  {
          switch (check_level[i])
    {
       case 'A':
             check_point[i]=8.0;
             break;
       case 'B':
             check_point[i]=6.0;
                break;
       case 'C':
            check_point[i]=4.0;
            break;
      case 'D':
            check_point[i]=2.0;
            break;
      case 'E':
            check_point[i]=0.0;
            break;
    }
  }
    else printf("输入错误!请重新输入!");

  total1+=check_point[i]*check_credit[i];
  total_credit1+=check_credit[i];
  }
  fflush(stdin);
 
 

 printf("请输入考试课的课数:");
  scanf("%d",&test_lessons);
  fflush(stdin);
    printf("请输入所有考试课成绩:");
       for(j=0;j<test_lessons;j++)
  scanf("%f",&test_mark[j]);
    fflush(stdin);
  printf("请输入所有考试课的学分:");
  for(j=0;j<test_lessons;j++)
  {
  scanf("%f",&test_credit[j]);
  if(test_mark[j]<=60)
   test_point[j]=0.0;
  else
  test_point[j]=(test_mark[j]-50)*0.2;
      total2+=test_point[j]*test_credit[j];
           total_credit2+=test_credit[j];
  }

   
    //考试课计算
  printf("\n您的平均学分为: %.5f\n",((total1+total2)/(total_credit1+total_credit2)));
  if(((total1+total2)/(total_credit1+total_credit2))>=6.0)
  {
   printf("************************************************\n");
   printf("*  Congratulations!You have won scholarship!   *\n");
   printf("************************************************\n");
  }
  else
   printf("\nWork hard and you will win scholarship next time.\n");
  fflush(stdin);

       getchar();
}

以后我会继续努力的!奋斗

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值