Finally got this C program to run but can't figure out the standard deviation problem

This is a discussion on Finally got this C program to run but can't figure out the standard deviation problem within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I lurk these forums a good amount but never registered to post myself. I have this C++ assignment ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    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:
    Code:
    #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 test
    //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...

    Code:
    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!


    I apologize for the poor formatting before.
    Last edited by theipodpeople; 03-20-2011 at 01:36 PM. Reason: Code tags etc

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You didn't think that when the forum warned you a dozen times that you needed code tags, that you should actually use code tags? You're also on the C++ forum, not the C forum. No one wants to read code with no indentation.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    fixed the code... bump? :]

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wordcounting program, problem with filereading.
    By Hemulen in forum C Programming
    Replies: 11
    Last Post: 11-06-2010, 02:20 PM
  2. standard deviation program
    By vietkhang123 in forum C++ Programming
    Replies: 2
    Last Post: 09-29-2010, 04:01 PM
  3. Problem with my program i cant figure out...
    By youareafever in forum C Programming
    Replies: 7
    Last Post: 11-01-2008, 11:56 PM
  4. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 02:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21