Hi I just finished my code for this program I am working on that is due today. I am having 1 problem and I can't seem to figure it out. My averages are being totalled way too high...I've been up midnight working on this. Any help/tips would be greatly appreciated ^_^
here is my code:
insert
Code:
//Mario Iglesias
//Date: 03/30/2011
//COP3223
//UF Idol 2
#include <stdio.h>
#include <math.h>
int main (void) //the begining of the program
{
//Local Variables
FILE* file_in; // Varable for the input file
int num_show; // (n) number shows to compute
int num_cont; // (c) number of contestants being scored
int num_judge; // (a) number of judges scoring contestants
int stDev_thre; // (s) threshold Standard Deviation
int i,j,k,l,x,y, z; // Loop Counters
int num_cheat; // Number of judges whos scores will be dropped
int n;
int winner; //Sample size used in StDev calculations
float deviation; // Holds individual deviations
float sum; // used for StDev summation
float sumsqr; // used for StDev summation
float mean; // Sample Mean for StDev
float variance; // s^2 used for StDev
float stDev; // Calculated StDeviation
int avg = 0; // hold the number of the winner contestant
float winAvg = 0; //holds the winners average score
file_in = fopen("ucfidol2.txt", "r"); //Opens file for reading
if(file_in == NULL) //Displays Error message to user if file_in = Null
{
printf("It appears that the file does not exist. Please check you folder.\n");
printf("And re-run Program\n\n");
system("PAUSE");
exit(0);
}
fscanf(file_in, "%d", &num_show); //reads in the number of shows to process
//Loop gathers data for each show and calls the appropriate functions to compute the results
//Will iterate once for each show. Displaying results at the end of each iteration
for(z =0;z<num_show;z++)
{
num_cheat = 0;
fscanf(file_in,"%d %d %d",&num_cont, &num_judge, &stDev_thre);
int scores[num_cont][num_judge]; //Array to hold scores for each contestant
int unfair[num_judge]; //holds index of unfair judges
//Outer/inner for loops read in show data for processing, And stores in 2D-array
for(j=0;j<num_cont;j++)
{
for(k=0;k<num_judge;k++)
{
fscanf(file_in,"%d",&scores[j][k]);
}
}
//calculate judge standard deviation per judge
float value [num_cont]; //holds value used in summation
i=j=k = 0; //clears loop counters for reuse
//Following three for loops used to compute the standard deviation for
//an individual show.
for (l=0; l< num_judge ; l++)
{
sum = sumsqr = n = 0 ;
//Computes summations needed to calculate the mean
for(i=0;i<num_cont;i++)
{
value[i] = scores[i][l];
sum += value[i];
n += 1;
}
mean = sum/(float)n; //Last step in calculation of the Mean
//computes summations needed to calculate the variance (s^2)
for (j=0; j<n; j++)
{
deviation = mean - value[j];
sumsqr += (deviation*deviation);
}
variance = sumsqr/(n-1) ; //Last step for computing variance
stDev = sqrt(variance); //Last step for computing St Deviation
//compare each judge standarddev to standardDev threshold
if(stDev - 1.857> stDev_thre)
{
num_cheat++;
unfair[k] = l;
k++;
printf("%d", unfair[k-1]);
}
//in the calculation of averages.
for(x=0;x<num_cont; x++)
{
for(y=0;y<num_judge; y++)
{
avg += scores[x][y];
for(k=0; k<num_cheat; k++)
{
scores[x][unfair[k]]=0;
}
}
if(winAvg<avg)
{
winner = (x+1);
winAvg = avg ;
if(num_cheat == 0 || (num_cheat + 1)== num_judge)
winAvg /= num_judge;
else
winAvg/= (num_judge-num_cheat);
}
}
}
//calculate averages with/without appropriate judge
//print results
printf("UF IDOL SHOW # %d \n\n\n", (z+1));
printf("Contestant # %d, You are the winner with an score of %.2f\n\n", winner, winAvg);
if(num_cheat == 0 || (num_cheat + 1)== num_judge)
{
printf("All Judges scores were used!\n");
}
else
{
printf("These judges Scores were not used: Judges #'s");
for(l=0; l<num_cheat; l++)
printf("%d, ", unfair[l] + 1);
}
printf("\n\n\n");
}
system("pause");
}//End Main