title: C programming - What am I doing wrong with these functions?
body: <p>This program I've written is supposed to ask for salaries, figure out the min, max value, average, median, and then sort them in decending order and display it. The program runs, but the max, min, avg, and the amount of salaries are completely off. I've been searching, re-reading and just can't figure out where I'm going wrong. Please help!!! </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  /* Function Prototypes */
  
  int get_number_of_salaries (void);
  
  void enter_salaries (int [], int);
  
  void sort (int [], int);
  
  void ending_sort (int [], int); 
  
  float get_median (int [], int);
  
  float average (float []);
  
  int minimum_value (int [], int);
  
  int maximum_value (int[], int);
  
  
  
  /* Functions */
  
  int get_number_of_salaries (void)
  {
      int number_of_salaries;
  do
  {
      printf ("Enter the number of salaries to process (2-100): ");
      scanf ("%i", &amp;number_of_salaries);
      fflush(stdin);
  
      if (number_of_salaries &lt;= 1)
          printf (" I'm sorry, you need to enter more than one salary.\n\n");
      if (number_of_salaries &gt; 100)
          printf (" I'm sorry, you can not enter more than 100 salaries.\n\n");
  
  } while (number_of_salaries &lt;= 1 || number_of_salaries &gt; 100);
  
  return number_of_salaries;
  
  }
  
  void enter_salaries ( int salaries [], int number_of_salaries)
  
  {
  int i;
  
  
  for ( i = 1; i &lt;= number_of_salaries; ++i)
  {
      do 
      {
          printf (" Enter salary #%i: ", i);
          scanf ("%i", &amp;salaries[i]);
          fflush(stdin);
  
          if (salaries[i] &lt;= 0)
              printf (" *** Invalid salary entered. Please re-enter. *** \n");
  
      } while (salaries[i] &lt;= 0);
  
  
  
  } 
  
  printf ("\n");
  
  }
  
  int minimum_value (int salaries [], int number_of_salaries)
  {
  int minimum, i;
  
  minimum = salaries [0];
  
  for (i = 1; i &lt; number_of_salaries; ++i)
      if (salaries [i] &lt; minimum)
          minimum = salaries [i]; 
  
  return minimum;
  
  }
  
  
  int maximum_value (int salaries [], int number_of_salaries)
  {
  int maximum, i;
  
  maximum = salaries [0];
  
  for (i = 1; i &lt; number_of_salaries; ++i)
      if (salaries [i] &gt; maximum)
          maximum = salaries [i];
  
  return maximum;
  
  }
  
  float average ( float a[])
  {
  int i, number_of_salaries;
  float avg, sum = 0.0;
  for (i = 0; i &lt; number_of_salaries; ++i)
  {
      sum += a[i];
  }
  
  avg = (sum/number_of_salaries);
  
  return avg;
   }
  
   void sort (int salaries [], int number_of_salaries)
  
   {
  
  int i, j, temp;
  
  
      for (i = 0; i &lt; number_of_salaries - 1; ++i)
          for (j = i + 1; j &lt; number_of_salaries; ++j)
          if (salaries [i] &gt; salaries [j])
          {
  
              temp = salaries[i];
              salaries[i] = salaries[j];
              salaries[j] = temp;
          }
  
  
  
  } /* end swap */
  
  float get_median (int salaries[], int number_of_salaries)
  {
  float temp;
  int x, i;
  
  for (x = 0; x &lt; number_of_salaries; ++x)
  for (i = x + 1; i &lt; number_of_salaries; ++i)
  {
      if (salaries[x] &gt; salaries [i])
      {
          salaries[i] = temp;
          salaries[i] = salaries[x];
          salaries[x] = temp;
      }
  }
  
  if (number_of_salaries % 2 == 0)
  return (salaries[number_of_salaries / 2] + salaries[number_of_salaries / 2 - 1]) / 2;
  else
  return salaries[number_of_salaries / 2];
  printf (" The median salary is %.1f \n", get_median);
  
  }
  
  void ending_sort (int salaries[], int number_of_salaries)
  {
  int i, j, temp;
  
  
  
      for (i = 0; i &lt; number_of_salaries - 1; ++i)
          for (j = i + 1; j &lt; number_of_salaries; ++j)
          if (salaries [i] &lt; salaries [j])
          {
              temp = salaries[i];
              salaries[i] = salaries[j];
              salaries[j] = temp;
          }
  }
  
  
  int main (void)
  {
  /* Variable Declarations */
  /*-----------------------*/
  int salaries [100];
  int number_of_salaries, maximum, minimum, x, i; 
  float avg;
  int total_salary;
  float median;
  
  /* Output Greeting */
  /*---------------------------------------------------*/
  printf (" Welcome to the Salary Calculator.\n");
  
  
  
  
  number_of_salaries = get_number_of_salaries ();
  
  enter_salaries (salaries, number_of_salaries);
  
  minimum_value (salaries, number_of_salaries);
  
  maximum_value (salaries, number_of_salaries);
  
  printf (" The minimum salary is %i \n", minimum);
  
  printf (" The maximum salary is %i \n", maximum);
  
  printf ("\n"); /* Spacing. */
  
  average (salaries);
  
  printf (" The average salary rounded is %i \n", avg);
  
  sort (salaries, number_of_salaries);
  
  get_median (salaries, number_of_salaries);
  
  median = get_median (salaries, number_of_salaries);
  
  printf (" The median salary is %.1f \n", median);
  
  ending_sort (salaries, number_of_salaries);
  
  printf (" The salaries entered were: \n");
  for (x = 1; x &lt; number_of_salaries; ++x)
      printf ("%i", salaries[x]);
  
  
  
  printf ("\n");
  
  
  getchar ();
  
  } /* End Main */
  </code></pre>