首页 > 解决方案 > 如何计算输入的数字?

问题描述

程序应该运行的方式是计算用户输入和输出该组中有多少个数字。

#include <stdio.h>

int main () {
    
    int input;
    int sum = 0;
    int count = 0;
    int hiprc, avgprc, loprc;
    int avg;
    
    while (input != -99)
    {
        printf("Enter the price (-99 to stop): ");
        scanf("%d", &input);
        sum = sum + input;
        count++;
    }

    if (hiprc = input >= 85)
    printf("Number of high prices is \n", hiprc);
    
    if (avgprc = hiprc < input && input > loprc)
    printf ("Number of average prices is \n", avgprc);
    
    if (loprc = input >= 60)
    printf ("Number of low prices is \n", loprc);

    avg = sum/count;
    printf("Average Price is %.2f\n", avg);
    
    return 0;
}

当我运行它时,它显示最高价格,添加平均价格,并为低价输出 0。它应该输出高、平均和低的数字。

High prices: 4
Average Prices: 15
Low Prices: 3

The average price is: xx.xx

这是用一些评论建议编辑的

标签: c

解决方案


if(hiprc < input > loprc)与数学中的含义不同。

改为使用if(hiprc < input && input > loprc)


推荐阅读