Hi:

I want to inputed salaries from loop and compare the max profit and min profit among salaries. When exit the loop should display the largest profit and smallest profit.

Problem occur when
1. Salary0 = 12000
2. Salary1 = 0
3. Salary2 = 6
4. Salary3 = 0
Output is
Max = 6.0
Min = 6.0

Can someone please help, I tried to fixed the problem many time still can't fix the problem.

See below for sample output and code:

Enter number of months in the financial period: 4
Enter the sales of month 1: ($)12000
Enter the sales of month 2: ($)0
Enter the sales of month 3: ($)6
Enter the sales of month 4: ($)0
Total sales: $12006.000000
Average monthly sales: $3001.500000
Maximum sales: $12000.000000
Minimum sales: $0.000000
Maximum sales rise: $6.000000
Minimum sales drop: $6.000000

Code:
#include <stdio.h>

int main() {
  int monthPeriod;
  float salary;
  float tempMin, tempMax;
  float tempSalary;
  float min, max;
  float profit, tempProfit;
  float maxProfit, minProfit;
  float tmpMinProf, tmpMaxProf;
  float sum;
  int month;

  printf("Enter number of months in the financial period: ");
  scanf("%d", &monthPeriod);

  if( monthPeriod < 0 )
    sum = min = max = 0;

  month = 1;
  printf("Enter the sales of month %d: ($)", month);
  scanf("%f", &salary);

  /* Initial values */
  tempMin = salary;
  tempMax = salary;
  min = salary;
  max = salary;

  /*Copy value of salary; value will change in loop*/
  tempSalary = salary;

  /*Initial value for profit*/
  tempProfit = tmpMaxProf = tmpMinProf = 0;

  /* Month = 2; Start loop */
  month++;
  sum = salary;

  while( month <= monthPeriod ) {
    printf("Enter the sales of month %d: ($)", month);
    scanf("%f", &salary);

    if( salary >= tempMax ) {
       tempMax = salary;
       max = tempMax;
    }//End if

    if( salary <= tempMin ) {
       tempMin = salary;
       min = tempMin;
    }//End if

    /*Find profit    */
    profit = salary - tempSalary;
    if(profit >= tempProfit) {
      tmpMaxProf = profit;
      maxProfit  = tmpMaxProf;
    }//End if

    if(profit < tempProfit) {
      tmpMinProf = -profit;
      minProfit  = tmpMinProf;
    }

    /*Update value*/
    tempProfit = profit;
    tempSalary = salary;

    sum = sum + salary;
    month++;
  }/*End loop*/

  printf("Total sales: $%f\n", sum);
  printf("Average monthly sales: $%f\n", sum/monthPeriod);
  printf("Maximum sales: $%f\n", max);
  printf("Minimum sales: $%f\n", min);
  printf("Maximum sales rise: $%f\n", maxProfit);
  printf("Minimum sales drop: $%f\n", minProfit);

  fflush(stdin);
  getchar();
  return 0;
}