I am having trouble finding the min and max in a list. I set up a run function so that it does not repalce the number with the next number in the list. Here is what I have and it will compile but the min and max use the number -999.
Code:
#include <stdio.h>
int factorial (int number);
int main ()
{
int count = 0, run = 1;
double number, sum, average, min, max;
sum = 0;
printf ("Please enter the numbers. Enter -999 when done.\n");
while (number != -999)
{
scanf ("%lf", &number);
if (number != -999)
{
sum += number;
count++;
}
}
if (count != 0)
{
average = sum/count;
if (run == 1) {
max=number;
min=number;
run=0;
}
if (number<min)
min=number;
if (number>max)
max=number;
count += 1;
printf ("The sum of the given list of number is %f.\n", sum);
printf ("The average of the given list of numbers is %f.\n", average);
printf ("The maximum number in the list is %f.\n", max);