#include <stdio.h>
float cabscore(float score)//返回值为小数形式,刚开始是定义为整数,会导致评委打分时不能进入下一个评委;
{
if(score>=0&&score<=10)
score=score;
else
{
printf("请重新输入分数");
scanf("%f",&score);
cabscore(score); }//避免再次给出一个不符合规则的数字
return score;
}
void calscore(int n)
{ int i=1;
//i代表评委的编号
float max=-1;
float min=11;
float ave=0,score,sum=0;
printf("请输入选手的成绩(0-10)\n");
do
{
printf("第 %d 位评委给分:", i);
scanf("%f", &score);
score=cabscore(score);//
sum+=score;
if(max<score)
max=score;
if(min>score)
min=score;
i++;
}while(i<=n);
//下面开始计算
ave = (sum-max-min)/(n-2);
printf("减去一个最高分: %.3f\n", max);
printf(", 减去一个最低分: %.3f\n", min);
printf("当前选手的最后得分是:%.3f\n", ave);
}
int main( )
{
int i,n;
double ave, score, sum, max, min;
char choice;
printf("请输入评委人数");
scanf("%d",&n);
do //计算选手的成绩,至少1次
{
calscore(n);
printf("******************* SUCCESS ***********************\n");
printf("按 N 退出,其他键继续....");
fflush(stdin); //将输入缓冲清空,否则getchar()会读入之前录入中的回车等符号
choice=getchar();
}while(choice!='N' && choice!='n'); //不管输入大小写,全算数
return 0;
}
软件工程报告2大奖赛计分
最新推荐文章于 2017-06-04 14:05:24 发布
作者 郭聪