/* Peter Cline, June 20, CISC105
   Fun with arrays and for loops
	Adding functions to the mix
	Finding average/max/min of an array of temperatures
*/

#include <stdio.h>
#define NUM_DAYS 10

void getTemperatures(double temperatures[]);
void printTemperatures(double temperatures[]);
void printAverage(double temperatures[]);
void printMax(double temperatures[]);

int main()
{
  double temps[NUM_DAYS] = {88.5, 60, 32, 90.7, 67.8,
                            75.3, 55.2, 85.3, 88.8, 77.7};
  int userInput;

  printf("Menu:\n");
  printf(" 1) Enter new temperatures\n");
  printf(" 2) Print temperatures to screen\n");
  printf(" 3) Print average of temperatures\n");
  printf(" 4) Print maximum temperature\n");
  printf("Your choice? ");
  scanf("%d", &userInput);
  
  if (userInput == 1) 
    getTemperatures(temps);
  else if (userInput == 2) 
    printTemperatures(temps);
  else if (userInput == 3)
    printAverage(temps);
  else if (userInput == 4)
    printMax(temps);
  else
    printf("You fail.  Sorry.\n");

  return 0;
}

// read in the temperatures from the user
void getTemperatures(double temperatures[])
{
  int day;

  printf("Enter %d temperatures:\n", NUM_DAYS);
  for (day = 0; day < NUM_DAYS; day++)
    {
      printf(" > ");
      scanf("%lf", &temperatures[day]);
    }
}

// printing out those ten temperatures
void printTemperatures(double temperatures[]) 
{
  int day;
 
  printf("Here are your temperatures:\n");
  for (day = 0; day < NUM_DAYS; day++)
    printf("Day %d had temperature %lf\n", day+1, temperatures[day]);
}

// calculate the average
void printAverage(double temperatures[])
{
  int day;
  double sum = 0;
  double average;
 
  for (day = 0; day < NUM_DAYS; day++)
    sum += temperatures[day];
  average = sum / NUM_DAYS;
  printf("Average temperature is: %lf\n", average);
}

// calculate the maximum temperature
void printMax(double temperatures[])
{
  int day;
  double max;
 
  max = temperatures[0];
  for (day = 0; day < NUM_DAYS; day++)
    if (max < temperatures[day])
      max = temperatures[day];

  printf("Max temp is: %lf\n", max);
}
