Min and max in C using basics

前端 未结 4 1174
鱼传尺愫
鱼传尺愫 2021-01-24 22:04

This program is supposed to end when the user enters 0 and then show the count, sum, average, min and max. I am able to figure out the sum count and average but my min and max i

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-24 22:24

    You used:

    if (number > 0)
    {
        count = count + 1;
        sum += number;      
        min = number;
        max = number;
    }
    

    Here, don't use:

    min = number;
    max = number;
    

    Because, when number is greater than 0, min and max value will be set to the input number so the if and else if statement below it, will not work.

提交回复
热议问题