这是自己学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();
}
以后我会继续努力的!