zhihongchan
2021-05-19 19:50
采纳率: 83.3%
浏览 22
已结题

C语言题目。电脑小白完全懵逼[face]emoji:011.png[/face]

C语言题目。电脑小白完全懵逼[face]emoji:011.png[/face]
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • benbenli 2021-05-20 02:33
    最佳回答
    
    #include <stdio.h>
    
    int main()
    {
        int n = 0;
        float sum = 0;
        while (1)
        {
            float g;
            printf("Enter a grade (0-100) [-1 to end]:\n");
            scanf("%f", &g);
            if (g == -1)
                break;
            else if (g > 100 || g < 0) 
            {
                printf("Marks out of range.\n");
                continue;
            }
            else if (g >= 80)
                printf("Excellent\n");
            else if (n >= 65)
                printf("Very Good\n");
            else if (g >= 50)
                printf("Average\n");
            else if (g >= 40)
                printf("Poor\n");
            else
                printf("Fail\n");
            
            ++n;
            sum += g;
        }
        
        
        printf("The total mark is %.2f, and the average is %.2f\n", sum, sum / n);
        
        return 0;    
    }
    
    // output:
    Enter a grade (0-100) [-1 to end]:
    10
    Fail
    Enter a grade (0-100) [-1 to end]:
    60
    Average
    Enter a grade (0-100) [-1 to end]:
    89
    Excellent
    Enter a grade (0-100) [-1 to end]:
    -2
    Marks out of range.
    Enter a grade (0-100) [-1 to end]:
    200
    Marks out of range.
    Enter a grade (0-100) [-1 to end]:
    38
    Fail
    Enter a grade (0-100) [-1 to end]:
    -1
    The total mark is 197.00, and the average is 49.25
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题