dropping the lowest test score

This is a discussion on dropping the lowest test score within the C++ Programming forums, part of the General Programming Boards category; I'm new to this site and a beginner in C++ programming so I'm still learning. I modify my program so ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    1

    dropping the lowest test score

    I'm new to this site and a beginner in C++ programming so I'm still learning. I modify my program so that the lowest test score is drop and this score should not be included in the calculation of the average. Any help is deeply appreciated.

    This is the part I modify in the program and I'm getting errors in this part:
    Code:
        int min;
        int nn=0;
        for (int count = 0; count < numScores; count++)
        {
            total += scores[count];
            if(count==0)min=scores[count];
            else if(scores[count]<min) 
            {
                min=scores[count]; nn=1;
            }
            else if(scores == min)nn++;  
        }
    This is the whole program:
    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    
    void arrSelectSort(double[], int);
    void showArrPtr(double[], int);
    int main()
    {
        double *scores,         // To dynamically allocate an array
            total = 0.0,      // Accumulator
            average;          // To hold average scores
        int numScores;            //Counter variable    
        
        cout << "How many test scores would you like to enter? ";
        cin >> numScores;
    
    
        // Dynamically allocate large array to hold test number.
        scores = new double[numScores];
        // Get the test scores
        cout << "Enter the test scores below.\n";
        for (int count = 0; count < numScores; count++)
        {
            cout << "Score " << (count + 1) << ": ";
            cin >> scores[count];
            if (scores[count] < 0)
            {
                cout << " \nNegative test values are not possible.\n";
                cout << "Please run the program again and enter a positive integer.\n";
                while (scores[count] < 0);
            }
        }    
        // Calculate the total of the scores
        
        int min;
        int nn=0;
        for (int count = 0; count < numScores; count++)
        {
            total += scores[count];
            if(count==0)min=scores[count];
            else if(scores[count]<min) 
            {
                min=scores[count]; nn=1;
            }
            else if(scores == min)nn++;
        }
    
    
        // Calculate the average score.
        average = total / numScores;           
        //  Display the results.
        cout << fixed << showpoint << setprecision(2);
        cout << "Average Score: " << average << endl;
        // Display the donations using the array of pointers. This
        // will display them in sorted order.
        cout << "The scores are sorted in ascending order: \n"; 
        arrSelectSort(scores, numScores); 
        showArrPtr(scores, numScores);
        // Free dynamically allocated memory
        delete [] scores;
        scores = 0;
        cout << endl;      
        system("PAUSE");
        return 0;                       
    }                                                            
    void arrSelectSort(double array[], int size)
    { 
        int startScan, minIndex;
        double minElem;
        for (startScan = 0; startScan < (size - 1); startScan++)
        {
            minIndex = startScan;
            minElem = array[startScan];
            for (int index = startScan + 1; index < size; index++)
            {
                if (array[index] < minElem)
                {
                    minElem = array[index];
                    minIndex = index;
                }
            }
            array[minIndex] = array[startScan];
            array[startScan] = minElem;
        }
    }
    void showArrPtr(double array[], int size)
    { 
        for (int count = 0; count < size; count++)
            cout << array[count] << " ";
        cout << endl;
    }

  2. #2
    DRK
    DRK is offline
    Registered User
    Join Date
    Jun 2009
    Posts
    109
    Code:
    while (scores[count] < 0);
    It's not very kind to loop the program forever.

    Code:
    else if(scores == min)nn++;
    You have forgotten to use [] operator here.

    To rule out the lowest score you need find it first and then calculate total score without including the lowest one(s).
    Last edited by DRK; 04-13-2012 at 02:29 AM.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    It should be pretty obvious, if you've already sorted it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculating Average and high/lowest test score
    By aexi in forum C++ Programming
    Replies: 4
    Last Post: 07-26-2010, 01:54 AM
  2. Replies: 3
    Last Post: 02-22-2009, 01:54 PM
  3. help on dropping score.
    By jchopki in forum C Programming
    Replies: 4
    Last Post: 09-21-2008, 06:54 PM
  4. Lowest Score Drop
    By naya22 in forum C++ Programming
    Replies: 16
    Last Post: 04-29-2007, 12:48 AM
  5. lowest test score
    By brown34 in forum C++ Programming
    Replies: 1
    Last Post: 05-11-2002, 12:02 PM

Tags for this Thread


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