// Arup Guha
// 10/12/09
// Powerball example developed in class to show use of arrays
// and processing large amounts of data.

// This program processes all the files with a multiplicative factor.

#include <stdio.h>

#define MAX_NUM 59
#define NUM_CHOICES 5
#define MULTS 5

int main() {
    
    // Open the file.
    FILE *ifp;
    ifp = fopen("powerball-59.txt","r");
    
    // Read in the number of drawings.
    int i, j, numdrawings;
    fscanf(ifp, "%d", &numdrawings);
    
    // Keeps track of regular numbers.
    int freq[MAX_NUM+1];
    for (i=0; i<=MAX_NUM; i++)
        freq[i] = 0;
        
    // Keeps track of the power ball.
    int power[MAX_NUM+1];
    for (i=0; i<=MAX_NUM; i++)
        power[i] = 0;
        
    // Keeps track of the multiplicative factors.
    int mult[MULTS+1];
    for (i=0; i<=MULTS; i++)
        mult[i] = 0;
        
    // Cycle through each drawing.
    for (i=0; i<numdrawings; i++) {
        
        int tempnum;
        
        // Read in first five numbers.
        for (j=0; j<5; j++) {  
            fscanf(ifp, "%d", &tempnum);
            freq[tempnum]++;
        }
        
        // Process powerball.
        fscanf(ifp, "%d", &tempnum);
        power[tempnum]++;
        
        // Process multiplier
        fscanf(ifp, "%d", &tempnum);
        mult[tempnum]++;
    }
    
    // Print out regular number chart.
    printf("Value\tPercentage\n");
    for (i=1; i<=MAX_NUM; i++) 
        printf("%d\t%.2lf\n", i, 100.0*freq[i]/numdrawings/NUM_CHOICES);
    printf("\n\n");
    
    // Print out Powerball chart.
    printf("Value\tPercentage\n");
    for (i=1; i<=MAX_NUM; i++) 
        printf("%d\t%.2lf\n", i, 100.0*power[i]/numdrawings);
     printf("\n\n");
     
    // Print out multiplier chart.
    printf("Value\tPercentage\n");
    for (i=1; i<=MULTS; i++) 
        printf("%d\t%.2lf\n", i, 100.0*mult[i]/numdrawings);

    // Find the most frequent value.
    int max = freq[1];
    int value = 1;
    for (i=2; i<=MAX_NUM; i++) {
        if (freq[i] > max) {
            max = freq[i];
            value = i;
        }
    }
    printf("\n\nMost frequent value was %d, it appeared %d times.\n", value, max);
    
    system("PAUSE");
    return 0;
}
