Thread: Lowest Score Drop - C++

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    4

    Lowest Score Drop - C++

    Hi everyone, I'm relatively new at C++ - knowning most of the basic rules and various structures of a C++ program - but I'm having a hard time developing a code - without the use of an arry (haven't learned it yet) - that determines the lowest number and drops it when calculating the average of a set of numbers. Here's the question:

    "Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions:

    void getScore() - should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered.

    void calcAverage() should calculate and display the average of the four highest scors. This function should be called just once by main, and should be passed the the five scores.

    int findLowest() should find and return the lowest of the five scores passed to it. It should be called by calcAverage, who uses the function to determine which of the five scores to drop.

    * Do not accept test scores lower than 0 or higher than 100."

    This is what I have so far:
    Code:
    //#4: Lowest Score Drop
    #include <iostream>
    using namespace std;
    
    //Function Prototypes
    void getScore(int); 
    void calcAverage();        
    int findLowest();          
    
    int main()
    {
        int testScore,
            sum = 0,       
            count;
        
        double testAverage;
        
        char restartProgram;
        
        cout <<"This program will calculate the average of five test scores, where the" << endl;
        cout <<"lowest score in the group is dropped." << endl;
        do{
             for(count = 1; count <= 5; count++)
             {
             cout <<"Please enter the score for test " << count <<"." << endl;
             cin  >> testScore;
                  if(testScore < 0 || testScore > 100) // Checks to see if input is valid: 
                                                       //0 <= testScore <= 100
                  {
                  cout << testScore << " is invalid. Please enter a score that is greater" << endl;
                  cout <<"than or equal to 0 or less than or equal to 100." << endl;    
                  break; // breaks out of if statement            
                  }
                  else
                  {
                  sum += testScore;
                  }
         getScore(sum);                
             }
        cout <<"Do you wish to restart the program?(y/n)" << endl;
        cin  >> restartProgram;
          }while(restartProgram == 'y' || restartProgram == 'Y');
    
    //Continue rest of program later...    
        
        
    system("pause"); //used for Dev C++
    return 0;   
    }
    I know how to write the code for calculating, calling other functions, etc., but I'm stuck at how to write a code that finds the lowest test score - inputed by the user - and drops it. I think I may need to edit how I did the for statement, but not really sure.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Hint:
    oid calcAverage() should calculate and display the average of the four highest scors. This function should be called just once by main, and should be passed the the five scores.
    This implies that you are going to need to store each test score into its own variable.

    Once you realize that, that might make the idea of "finding the lowest score" a little more palatable.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    4
    Quote Originally Posted by tabstop View Post
    Hint:

    This implies that you are going to need to store each test score into its own variable.

    Once you realize that, that might make the idea of "finding the lowest score" a little more palatable.
    I understand what you mean, but I ran into a problem before I decided to just use a single testScore variable than 5 separate variables. Here's what problems arised: what if all the scores are exactly equal and how would I create a code to test five scores - in this case, every score is different. I thought about using an if, if/else, or if/else if statement, but I'm too confused on where to start.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    (0) Note: using a single testScore variable is not an option, given that it will make it impossible to complete the assignment -- both in that you won't be able to follow the guidelines, and that you won't be able to compute the correct answer at all (without at least one additional variable)!

    (1) If all the scores are exactly equal, then it doesn't matter which one you claim is lowest -- if I give you 80, 80, 80, 80, and 80, the lowest score is going to have to be 80, right?

    (2) Suppose I give you the numbers
    75
    79
    65
    82
    73
    How do you know which number is the smallest? Can you write down what you did? (If not, why not?) What about if I gave you the numbers one at a time?

  5. #5
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Let's say you get 5 scores and they are all 20. I suspect the assignment is not to drop all 5 of the 20's, rather just one of them.

    Todd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting lowest and highest score from array
    By sjalesho in forum C Programming
    Replies: 6
    Last Post: 03-01-2011, 06:24 PM
  2. C program using structs to calculate grades
    By TampaTrinDM88 in forum C Programming
    Replies: 4
    Last Post: 07-06-2009, 12:33 PM
  3. trouble with creating a loop to read certain number of inputs
    By import tuner650 in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2008, 07:28 PM
  4. Lowest Score Drop
    By naya22 in forum C++ Programming
    Replies: 16
    Last Post: 04-29-2007, 12:48 AM
  5. Drop Lowest Grade then Average
    By cmut in forum C Programming
    Replies: 4
    Last Post: 09-27-2002, 10:19 PM