Hey guys, thanks for your help. Unfortunately I'm still having trouble with the code. It only gives me the max, the min stays zero.
Here's the complete code:
Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
char buf[BUFSIZ + 1];
int count=0;
float input,sum;
min=32356;
max=-32356;
int main()
{
do {
printf("enter");
input=atof(gets(buf));
count++;
if (min > input)
min=input;
if (max < input)
max=input;
sum +=input;
//diagnostics
printf("input%i\n",input);
printf("count%i\n",count);
printf("max%i\n",max);
printf("min%i\n",min);
//
}
while (strlen(buf) > 0);
printf("\ncount %i\n",count-1);
printf(" min %i\n",min);
printf(" max %i\n",max);
printf(" ave %f\n",(sum/(count-1)));
return (0);
}
The printf tells me that while it's in the loop the min max and ave are all right, but when it finishes, the min is allways 0.
Here's the output:
enter 2
input 0
count 1
max 2
min 2
enter 5
input 0
count 2
max 5
min 2
enter 2
input 0
count 3
max 5
min 2
enter
input0
count4
max5
min0
entered 3
low 0
high 5
average 3.000000
At this point the low should be 2,
I'msure i'm making some stupid little mistake somewhere, it's just I don't know where..