Thread: My small programing problem

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    28

    Question My small programing problem

    Hello, Thank you for looking at this with me.

    Im currently writing a basic basic program to sort of take a couple grade for test, quizzes etc, display the results for each student entered, Ive got this basis down. Now what i am having a hard time with is this:

    1) the highest and lowest scores of the class.
    2) the avg scores of the entire class.

    i think for the high and low scores,i should use an if statement to determine whether or not the total points is higher or lower than the previous one and store the new value it if it is. But really i dont have the programming knowledge to do this.

    For the average,i should just keep adding the total points every loop then divide it by the number of students, but im not sure how to store each score and have it add it all up in the end.

    Any help would be greatly appreciated thank you!

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by kordric View Post
    Hello, Thank you for looking at this with me.

    Im currently writing a basic basic program to sort of take a couple grade for test, quizzes etc, display the results for each student entered, Ive got this basis down. Now what i am having a hard time with is this:

    1) the highest and lowest scores of the class.
    2) the avg scores of the entire class.

    i think for the high and low scores,i should use an if statement to determine whether or not the total points is higher or lower than the previous one and store the new value it if it is. But really i dont have the programming knowledge to do this.

    For the average,i should just keep adding the total points every loop then divide it by the number of students, but im not sure how to store each score and have it add it all up in the end.

    Any help would be greatly appreciated thank you!
    Code:
    int low_score, high_score; 
    
    //assign low_score and high_score to the very first student's score, then
    
    if(current_score < low_score)
       low_score = current_score;
    
    if(current_score > high_score), etc.
    You don't need to store each score. Just keep a tally, and when the last score has been added to the tally, then divide by the number of scores.

    Code:
    int tally, current_score, student_num;
    tally = student_num = 0;
    
    for (each student's score) 
       tally += current_score;
       student_num++;
    That should get you started.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    28
    Thanks, this helps a lot. The avgs just adds the score to the previous amout then right?

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    28
    What would got in between the for's ()? I having trouble with this part as well.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Quote Originally Posted by kordric View Post
    What would got in between the for's ()? I having trouble with this part as well.
    It's a loop. It typically goes for(initialize; check for; do what after each loop). Something like...

    Code:
    for(int n = 0; n < 100; n++){
        //stuff...
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Small Problem with double and integer adding?
    By Nathan the noob in forum C++ Programming
    Replies: 5
    Last Post: 03-28-2009, 04:16 PM
  2. Visual C++ small problem
    By gadu in forum C++ Programming
    Replies: 0
    Last Post: 03-10-2009, 10:45 PM
  3. Small problem with this array...
    By Merholtz in forum C Programming
    Replies: 7
    Last Post: 11-03-2008, 04:16 PM
  4. Help with a small problem (beginner)
    By piffo in forum C Programming
    Replies: 13
    Last Post: 09-29-2008, 04:37 PM
  5. Need Big Solution For Small Problem
    By GrNxxDaY in forum C++ Programming
    Replies: 8
    Last Post: 08-01-2002, 03:23 AM