Thread: finding highest average

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    8

    finding highest average

    I'm trying to figure out the code to determine the student with the highest average. I got this far but now I'm stuck.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define STUDENTS 4
    #define QUIZZES 5
    
    main() {
    
    	int quizScores[STUDENTS][QUIZZES] = {
    		{ 90, 90, 90, 90, 90  },
    		{ 90, 80, 70, 60, 50  },
    		{ 90, 89, 88, 87, 86  },
    		{ 90, 85, 80, 75, 70  }
    	};
    	int studentTotal = 0, quizTotal, row, col;
    	double studentAverage, quizAverage;
    
    for (row = 0; row < STUDENTS; row++) {
    	studentTotal = 0;
    	for ( col = 0; col < QUIZZES; col++) {
    		studentTotal += quizScores[row][col];
    	}
    	studentAverage = (double) studentTotal / QUIZZES;
    	printf("Student %i has average %.2lf\n", row, studentAverage);
    }
    	
    for ( col = 0; col < QUIZZES; col++){
    	quizTotal = 0; 
    	for( row = 0; row < STUDENTS; row++){
    		quizTotal += quizScores[row][col];
    	}
    	quizAverage = (double) quizTotal / STUDENTS;
    	printf("Quiz %i has average %.2lf\n", col, quizAverage); 
    }
    	
    //for (
    
    
    	//printf("Student %i has the highest average with a score of %.2lf\n", row, studentAverage);
    
    		
    		system("pause");
    }

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    What's the problem?

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    8
    I need to write code to determine which student has the highest average. So far I found the averages for all students and all quizzes but I can't figure how to find the highest.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Make 2 variables.

    highest_student and highest_score

    Initialize highest_score to 0.

    Go through each student, if the score is higher than highest score, set highest_student to that student, and highest_score to their score.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Or you can just use the one variable highest_student and compare the highest student's average with the current student's average.

  6. #6
    Registered User jephthah's Avatar
    Join Date
    May 2010
    Location
    seattle
    Posts
    49
    how is it that you can find the average of a set of numbers -- complete with #defines and floating point casts -- but cant find the highest value of a set of numbers?

    did you try?

    did you even write the code you posted?

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    8
    Hey guys thanks for your help! Figured it out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 02-22-2009, 02:54 PM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  3. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  4. Replies: 9
    Last Post: 11-20-2003, 08:55 PM
  5. Finding Average of floats
    By sonict in forum C++ Programming
    Replies: 8
    Last Post: 12-01-2002, 08:52 PM