My program is suppose to read multiple inputs and display the min, max, sum and the average. It is supposed to look like this:
Input:
2.5 5 3.5 4.5 jfkjk
output:
min is 2.5
max is 5
sum is 15.5
average is 3.875
The program is supposed to quit when it reaches a non-number or a newline. The user can input as many numbers as they like. I cannot use arrays and must use loops. This is what my program looks like:
void numbers()
{
double digit;
double sum = 0;
double avg = 0;
double max;
double min;
unsigned count = 0;
//int c;
max = 0;
printf("Input:");
do {
scanf("%lf", &digit);
min = digit;
if(max < digit)
digit = max;
if(min < digit)
digit = min;
sum += digit;
count++;
avg = sum/count;
} while( scanf("%lf", &digit)==1 )
printf(" min is %lf max is %lf sum is %lf avg is %lf count is %u", min, max, sum, avg, count);
}
prints out:
Input:2.2 2.3 5 3.5 blah
min is 3.500000 max is 0.000000 sum is 0.000000 avg is 0.000000 count is 4