首页 > 其他 > 详细

7.9 skippart.c 程序

时间:2019-04-13 14:22:31      阅读:157      评论:0      收藏:0      [点我收藏+]

7.9 skippart.c 程序

#include <stdio.h>
int main(void)
{
    const float MIN = 0.0f;
    const float MAX = 100.0f;
    float score;
    float total = 0.0f;
    int n = 0;
    float min = MAX;
    float max = MIN;
    printf("Enter the first score (q to quit): ");
    while (scanf("%f", &score) == 1)
    {
        if (score < MIN || score > MAX)
        {
            printf("%0.1f is an invalid value. Try again: ", score);
            continue;        // 跳转至while循环的测试条件
        }
    printf("Accepting %0.1f:\n", score);
    min = (score < min) ? score : min;
    max = (score > max) ? score : max;
    tota += score;
    n++;
    printf("Enter next score (q to quit): ");
    }
    if (n > 0)
    {
        printf("Average of %d scores is %0.1f.\n",  n, total / n);
        printf("Low = %0.1f, high = %0.1f\n", min, max);
    }
    else 
        printf("No valid scores were entered.\n");
    return 0;
}

7.9 skippart.c 程序

原文:https://www.cnblogs.com/EisNULL/p/10700948.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!