I'm trying to write a C code in codeblocks to ask a user for the amount of numbers they want to enter, then output the min, max, and average. the average and min are not working properly and the imput error is not working
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
float sum, min = 0, max = 0, mean = 0;
double x, y;
int i = 0, test = 0, test1 = 0;
do{
printf("How many values are to be entered?\n");
test1 = scanf("%f", &sum);
if(test1 == 0 || sum < 0)
{
while(getchar() != '\n');
printf("INPUT ERROR!\n");
test1 = 0;
}
}
while(test1 == 0);
printf("\n");
for(i = 1; i <= sum; i++)
do{
printf("Value %d: ", i);
test = scanf("%lf", &x);
if(test == 0);
{
while(getchar() != '\n');
printf("INPUT ERROR!\n");
}
}
while(test == 0);
y = y +x;
if(i == 1){
min = x;
max = x;
}
if(x > max){
max = x;
}
else if (x < min){
min = x;
}
mean = y / sum;
printf("The minimum value is %g, ",min);
printf("the maximum value is %g, ",max);
printf("and the average value is %g\n",mean);
return(0);
}