// Arup Guha
// 10/3/2011
// Written in COP 3223 - a weather program that uses arrays.

#include <stdio.h>

const int MAXSIZE = 20;
const int INVALID = -99;

int main() {

    FILE* ifp;
    char filename[MAXSIZE];

    // Get the file name and open it.
    printf("Enter the weather file.\n");
    scanf("%s", filename);
    ifp = fopen(filename, "r");

    // Create and initialize our frequency array.
    int temperatures[100];
    int i;
    for (i=0; i<100; i++)
        temperatures[i] = 0;

    // Go through each day of data.
    while (1) {

        // Get this day's reading.
        int month, day, year;
        double temp;
        fscanf(ifp, "%d%d%d%lf", &month, &day, &year, &temp);

        // No more data appears in the file.
        if (month == -1)
            break;

        // Only process valid data, in between 0 and 100 degrees.
        if (temp > INVALID) {
            int range = (int)temp;
            if (range >= 0 && range <= 99)
                temperatures[range]++;
        }
    }

    // Print out how many days for each temperature range.
    for (i=0; i<100; i++)
        printf("%d - %d: %d\n", i, (i+1), temperatures[i]);

    /*** Note, if we had only 10 ranges (0-10, 10-20, etc.) we would do
         the following:

         int range = (int)(temp/10); // in the if in the while
         for (i=0; i<10; i++)        // at the very end
             printf("%d - %d: %d\n", 10*i, 10*(i+1), temperatures[i]);
    ***/

    fclose(ifp);
    return 0;
}
