Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果(maxScoreexamScore) { minScore=examcore; } } 打破 案例2: printf(“最高考试分数为:%.2f\n”,maxScore); 打破 案例3: printf(“最低考试分数为:%.2f\n”,minScore); 打破 案例4: { float avgScore=sumScore/scoreCount; printf(“平均考试分数为:%.2f\n”,avgScore); 打破 } 违约: printf(“您输入的菜单选项无效,请仔细查看!”); 打破 } } 返回0; }_C - Fatal编程技术网

如果(maxScoreexamScore) { minScore=examcore; } } 打破 案例2: printf(“最高考试分数为:%.2f\n”,maxScore); 打破 案例3: printf(“最低考试分数为:%.2f\n”,minScore); 打破 案例4: { float avgScore=sumScore/scoreCount; printf(“平均考试分数为:%.2f\n”,avgScore); 打破 } 违约: printf(“您输入的菜单选项无效,请仔细查看!”); 打破 } } 返回0; }

如果(maxScoreexamScore) { minScore=examcore; } } 打破 案例2: printf(“最高考试分数为:%.2f\n”,maxScore); 打破 案例3: printf(“最低考试分数为:%.2f\n”,minScore); 打破 案例4: { float avgScore=sumScore/scoreCount; printf(“平均考试分数为:%.2f\n”,avgScore); 打破 } 违约: printf(“您输入的菜单选项无效,请仔细查看!”); 打破 } } 返回0; },c,C,有两个问题:负分数存储为最小值,但如果修复,则最小分数的初始值将为0,因此无法获得更高的值。 如果最小检查的输入不超过100(代码注释中的initA)或第一个值的init(基于分数计数-initB),则将最小分数初始化为100。 输入考试分数也可以通过提供超出范围的值来退出: float minScore = 100.0; /* initA */ /* .. */ case 1 : { printf("Enter an exam score (0..100): "

有两个问题:负分数存储为最小值,但如果修复,则最小分数的初始值将为0,因此无法获得更高的值。 如果最小检查的输入不超过100(代码注释中的initA)或第一个值的init(基于分数计数-initB),则将最小分数初始化为100。 输入考试分数也可以通过提供超出范围的值来退出:

float minScore = 100.0; /* initA */
/* .. */
    case 1 :
    {
        printf("Enter an exam score (0..100): "); scanf("%f", &examScore);
        while( ( 0.0 <= examScore ) && ( examScore <= 100.0 ) )
        {
            if( 0 == scoreCount ) { minScore = examScore; } /* initB */
            ++scoreCount;
            if( maxScore < examScore ) { maxScore = examScore; }
            if( minScore < examScore ) { minScore = examScore; }
            sumScore += examScore;
            avgScore = sumScore / scoreCount;
            printf("Enter an exam score (0..100): "); scanf("%f", &examScore);
        }
        break;
    }
float minScore=100.0;/*伊尼塔*/
/* .. */
案例1:
{
printf(“输入考试分数(0..100):”;scanf(“%f”),&examcore);

而((0.0
ExamCore
在初始化之前也被使用。其他的不属于那里…第一个分数是最小值和最大值。@JimBalter这是真的。我试着想一个例子,它必须同时执行这两个值,但我错过了一个明显的值。修复了。我已经写了40多年的代码,遇到了这个错误或一个l请注意,如果你想一个else会失败的例子,你不仅引入了一个bug,而且花了不必要的精力去想这个例子,你犯了过早优化的错误……这可能会适得其反;在现代机器中,额外的分支会导致代码运行错误更低。即使else有效,也应该避免。我仍在修复该终止值。我已对平均值进行了一些编辑和求解,并对ExamCore输入进行了错误检测。首先检查有效范围(以及终止的
-999
),然后如果该范围无效,则跳过循环的其余部分(
continue
将完成此操作)。摆脱!我几乎在我的机器上运行了此操作,我机器上的
pause
命令将暂停我家核反应堆的冷却系统。
int foo;
while (foo != 5) {
   foo = 5;
   do_stuff();
}
if(maxScore < examScore)
{
    maxScore = examScore;
}

if(minScore > examScore)
{
   minScore = examScore;
}
while(...) 
   printf("Enter an exam score (enter -999 to quit score input):\n");
   scanf("%f", &examScore);
   printf("The score you've entered equates to : %.2f\n\n", examScore);

   if(examScore < 0 || examScore > 100)
   {
       printf("Exam Scores range from 0.0 - 100.0\n");
       continue; //goes back to the top of the loop skipping everything else
   } 
   //At this point you know the score is valid so you can process it
   scoreCount++;

   if(maxScore < examScore)
   {
       maxScore = examScore;
   }
   if(minScore > examScore)
   {
      minScore = examScore;
   }
   sumScore += examScore;
   avgScore = sumScore / scoreCount;
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int scoreCount = 0;
    float maxScore = -1000.0,
          minScore = 1000.0,
          sumScore = 0.0;

    printf("************************************\n");
    printf("1-> Enter Exam Scores\n");
    printf("2-> Display the highest exam score\n");
    printf("3-> Display the lowest exam score\n");
    printf("4-> Display the average exam score\n");
    printf("5-> Quit the program\n");
    printf("************************************\n\n");

    for(;;)
    {
        int menuChoice;
        printf("Select a number that corresponds to the menu:\n");
        scanf("%d", &menuChoice);

        if(scoreCount == 0 && menuChoice >= 2 && menuChoice <= 4)
        {
            printf("Please enter some scores by choosing menu item 1\n");
            continue;
        }

        switch(menuChoice)
        {
        case 1:
            for(;;)
            {
                float examScore;
                printf("Enter an exam score (enter -999 to quit score input):\n");
                scanf("%f", &examScore);
                if (examScore == -999)
                    break;
                printf("The score you've entered equates to : %.2f\n\n", examScore);
                if(examScore < 0 || examScore > 100)
                {
                    printf("Exam scores range from 0.0 - 100.0\n");
                    continue;
                }

                sumScore += examScore;
                ++scoreCount;

                if(maxScore < examScore)
                {
                    maxScore = examScore;
                }
                if(minScore > examScore)
                {
                    minScore = examScore;
                }
            }
            break;

        case 2:
            printf("The highest exam score is : %.2f\n", maxScore);
            break;

        case 3:
            printf("The lowest exam score is : %.2f\n", minScore);
            break;

        case 4:
        {
            float avgScore = sumScore / scoreCount;
            printf("The average exam score is : %.2f\n", avgScore);
            break;
        }

        default:
            printf("You've entered an invalid menu choice, review more carefully!");
            break;
        }
    }

    return 0;
}
float minScore = 100.0; /* initA */
/* .. */
    case 1 :
    {
        printf("Enter an exam score (0..100): "); scanf("%f", &examScore);
        while( ( 0.0 <= examScore ) && ( examScore <= 100.0 ) )
        {
            if( 0 == scoreCount ) { minScore = examScore; } /* initB */
            ++scoreCount;
            if( maxScore < examScore ) { maxScore = examScore; }
            if( minScore < examScore ) { minScore = examScore; }
            sumScore += examScore;
            avgScore = sumScore / scoreCount;
            printf("Enter an exam score (0..100): "); scanf("%f", &examScore);
        }
        break;
    }