Hello,

I am trying to get output of the min max and mean (to 2 decimal place) of an arbitrary number of floating point inputs, each separated by a newline, from the keyboard. The range of inputs is restricted from -100000 to 100000.

Ex. Input: 7

5.6

6

Output:

5.60 7.00 6.20

My code below is allowing me to input as many values as I want but not able to get any output. I apologize for the formatting and would appreciate insight on how to format code properly here for posts.

#include<stdio.h>

#include<math.h>

Code:

#include<stdio.h>
#include<math.h>
int main(void)
{
int r = 0;//for scanf value
float i = 0;//for input
float min = 100001;
float max = -100001;
int count = 1;
float total = 0;
float mean = 0;
do
{
r = scanf("%f", &i);
if (r == EOF)//when user ctrl-d EOFs, print output
break;
else if (r == 0)//if there is an input not of type float, skip it and go to next
continue;
if (i < min)
i = min;
if (i > max)
i = max;
total = total + i;//running total
mean = total / count;
count++;
}while(r != EOF);
printf("%.2f %.2f %.2f\n", min, max, mean);//print 2 decimal places
return 0;
}