Why this cant run and need solution..

#include <stdio.h>
#include <limits.h>

int main(void)
{
int num, count, total, max, min;
float average;

// initialization
count = total = 0;
max = INT_MIN;
min = INT_MAX;

printf("Enter a series of integers terminated by a 0: \n");


while(scanf(" %d", &num)!= 0)
{
count++;
total += num;
if(max < num)
max = num;
if(min > num)
min = num;
average = total / count;

printf("You have entered %d integers\n", count);
printf("The average is %f\n", average);
printf("The maximum is %d\n", max);
printf("The minimum is %d\n", min);
}

return 0;
}
DeadF, what does it do that you think it shouldn't do?
closed account (z05DSL3A)
Maybe:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <limits.h>

int main(void)
{
    int num, count, total, max, min;
    float average;

    // initialization
    num = count = total = 0;
    max = INT_MIN;
    min = INT_MAX;
    average = 0.;

    printf("Enter a series of integers terminated by a 0: \n");


    while(scanf(" %d", &num) && num != 0)
    {
        
        count++;
        total += num;
        if(max < num)
            max = num;
        if(min > num)
            min = num;
        average = float(total) / float(count);
    }

    printf("You have entered %d integers\n", count);
    printf("The average is %f\n", average);
    printf("The maximum is %d\n", max);
    printf("The minimum is %d\n", min);

    return 0;
}
Enter a series of integers terminated by a 0:
1 2 3 4 5 6 0
You have entered 6 integers
The average is 3.500000
The maximum is 6
The minimum is 1



Enter a series of integers terminated by a 0:
1
2
3
4
5
6
0
You have entered 6 integers
The average is 3.500000
The maximum is 6
The minimum is 1
Last edited on
Topic archived. No new replies allowed.