Finally got this C program to run but can't figure out the standard deviation problem
Hey guys, I lurk these forums a good amount but never registered to post myself. I have this C++ assignment I'm working on that is now overdue and killing me! If anyone has any suggestions i'd greatly appreciate it!
Okay here's a link to the actual project. It's already overdue because I can't figure it out and get it to run no matter what I try!
http://www.cs.ucf.edu/courses/cop322...s/Program4.pdf
This is the code I have, completed:
#include <stdio.h>
#include <math.h>
int main() {
int num_shows, num_contestants, num_judges, sd_threshold;
double average;
// Open the text file.
FILE* ifp = fopen("ucfidol2.txt", "r");
//scanning info from text file
fscanf(ifp, "%d", &num_shows);
fscanf(ifp, "%d%d%d", &num_contestants, &num_judges, &sd_threshold);
//declaring array size by text file
int score[num_contestants][num_judges];
int i, j;
//populates 2d array with numbers from text file
for (i = 0; i < num_contestants + 1; i++)
for (j = 0; j < num_judges; j++)
fscanf(ifp, "%d", &score[i][j]);
int judges_score[num_judges];
int index;
for (i = 0; i < num_judges; i++)
scanf("%d", &average[i]);
int val = 0;
double sum = 0;
//adds judges scores together
for (val=0; val <= num_contestants-1; val++) {
sum = sum + score[val][0];
//testing
printf("val = %d\n", val);
printf("score[0][%d] = %d\n", val, score[val][0]);
printf("sum = %lf\n", sum);
}
//calculates average of judges scores
average = sum / num_contestants;
printf("average = %lf\n", average);
//NEED THIS CODE!!!
//printing
//printf ("%d\n", score[0][0]);
//printf ("%d\n", score[0][1]);
//printf ("%d\n", score[0][2]);
//printf ("%d\n", score[0][3]);
//printf ("%d\n", score[1][0]);
//printf ("%d\n", score[1][1]);
//printf ("%d\n", score[1][2]);
//printf ("%d\n", score[1][3]);
//printf("num_shows = %d\n", num_shows);
//printf("num_contestants = %d\n", num_contestants);
//printf("num_judges = %d\n", num_judges);
//printf("sd_threshold = %d\n", sd_threshold);
// Close the file.
fclose(ifp);
system("PAUSE");
return 0;
}
I can't figure out the rest of the code for the life of me, I've tried a few things
someone sent me this (has different variables but it's easier to see how it works) but I can't make it work and get anything to print out...
for (i=0; i<judges; i++) {
sum=0
for (j=0; j<contestants; j++) {
sum = ((pow(judavg[i]-score[j][i],2) + sum;
}
sd = sqrt(sum/cont);
if (sd > std)
cheaters[i]=1
else
cheaters[i]=0
Can anyone fill in the blanks for me? Also if I have any other errors please let me know!