c項目2

#include <stdio.h>
#include <stdlib.h>
void calScore(int );
void xianshi(float ,float, float,int );
int main()
{
    int n;//裁判的人數
    printf("輸入評委的人數(大於2人):\n");
    scanf("%d",&n);
    calScore(n);
    return 0;
}
/*************************************************************
功能描述:計算出正確的答案
輸入參數:n-評委人數
返 回 值:無
其他說明:無
/************************************************************/
void calScore(int n)
{
    char q='a';//控制程序是否繼續運行
    int i;//控制循環
    while(q!='n'&&q!='N')
    {
        float high=0.0,low=10.0,sum=0.0,score;//得分情況
        printf("請輸入選手成績(0-10)\n");
        for(i=0; i<n; i++)
        {
            printf("第%d位評委打分:",i+1);
            scanf("%f",&score);
            while(score<0||score>10)
            {
                printf("輸入錯誤,請重新輸入。\n");
                printf("第%d位評委打分:",i+1);
                scanf("%f",&score);
            }
            sum+=score;
            if(score>high)
                high=score;
            if(score<low)
                low=score;
        }
        xianshi(sum,low,high,n);
        fflush(stdin);
        scanf("%c",&q);
        if(q!='n'&&q!='N')
        {
            printf("\n");
            printf("輸入評委的人數(大於2人):\n");
            scanf("%d",&n);
        }
    }
}
/*************************************************************
功能描述:計算出正確的答案
輸入參數:sum-總分
low-最低分
high-最高分
n-評委人數
返 回 值:無
其他說明:無
/************************************************************/
void xianshi(float sum,float low,float high,int n)
{
    float aver;
    aver=(sum-low-high)/(n-2);
    printf("減去一個最高分:%.2f,去掉一個最低分:%.2f\n",high,low);
    printf("當前選手的最後得分是:%.2f\n",aver);
    printf("*************成功**************\n");
    printf("按N退出,按其他鍵繼續.....\t");
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章