// july31ex1.cpp : Defines the entry point for the console application.
// Input a series of pieces of paper.  Each slip has a Julian date 
// (1 - 365) and a temp
//Find the avg temp for each day in the year - that has a report

// INput - keep reading data until a day of -999 is found as a trailer

#include "stdafx.h"

void print_info(void);
float averages(void);

int count_day[366]={0};
float total_temp[366]={0.0};

int main(int argc, char* argv[])
{     int day;
    float temp;


    printf("Input Julian day and temp for each slip of paper.\n");
	printf("Type -999 for day to stop\n");

    scanf("%d", &day);
	while (day != -999) {
        scanf("%f", &temp);
		if ( (day<1) || (day>365) || (temp<-120) || (temp>125) )
			printf("Illegal input!  Please retype!!\n");
		else  {
                count_day[day]++;
				total_temp[day]+= temp;

		}   /* end else day */

        scanf("%d", &day);
	}   /* end while day */

	print_info();

	printf("\nThe average temp for entire year is %4.1f\n", averages() );


	return 0;
}   /* end main */

void print_info() {
     int day;
	 for (day=1; day<=365; day++) 
	    if (count_day[day] > 0)
		 printf("Day %3d had count of %2d and total temp of %4.1f \n",
		          day, count_day[day], total_temp[day]);

} /* end print_info */



float averages(void) {
	float year_tot = 0.0;
	int jour, year_count = 0;

	for (jour=1; jour<= 365; jour++) 
		if (count_day[jour] > 0) {

             year_count += count_day[jour];
			 year_tot += total_temp[jour];

			 printf("Avg temp or day %d was %4.1f\n", jour, total_temp[jour]/count_day[jour]);

		}  /* for jour */

		return year_tot / year_count;

} /* end function averages   */