Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8767803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:54:35+00:00 2026-06-13T16:54:35+00:00

Code works well except it doesn’t drop the lowest score and then calculates it.

  • 0

Code works well except it doesn’t drop the lowest score and then calculates it.

Output Example:

How many test scores would you like to enter?
3
Enter the test score desired:
Score 1: 58
Score 2: 96
Score 3: 78
Test Scores Average with the lowest dropped is: 116.00

Problem:
As you can see on the output example, that is incorrect. It must display the average not including the lowest. Could you review my code and let me know where I have gone wrong? I’ve had several people look at it too and they’ve not been able to see any bugs in my code. Below is my code:

Code:

#include <iostream>
#include <iomanip>

using namespace std;


int main()
{
    //To dynamically allocate an array, Accumulator, to hold the average scores.
    double *score;      
    double total = 0;  
    double average; 


    //int for counter, to hold the number of test scores.
    int count; 
    int numTest; 


    // To obtain the number of test scores the user would like to enter.
    cout << "How many test scores would you like to enter? " << endl;
    cin >> numTest; 


    //Dynamically allocates an array large enough to hold the amount of test scores to enter.
    score = new double[numTest];


    //Get the test scores.
    cout << "Enter the test score desired. " << endl;
    for (count = 0; count < numTest; count++)
    {
        cout << "Score " << (count + 1) << ": ";
        cin >> score[count];
    }

    //Find lowest score.
    int lowest = score[count];
    for (count = 1; count < numTest; count++)
    {
        if (score[count] < lowest) 
            lowest = score[0];
    }


    //Calculate the total test scores.
    for (count = 0; count < numTest; count++)
    {
        total += score[count];
        total -= lowest;
    }

    //Calculate the test scores average minus the lowest score. 
    average = total / (numTest - 1);

    //Display the results
    cout << fixed << showpoint << setprecision(2);
    cout << "Test Scores Average with the lowest dropped is: " << average << endl;

    //Free dynamically allocated memory
    delete [] score;
    score = 0; // Makes score point to null.

    system("pause");
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:54:36+00:00Added an answer on June 13, 2026 at 4:54 pm

    You have three significant errors in this code:

    First, the initial value of lowest:

    //Find lowest score.
    int lowest = score[count];  // ERROR
    for (count = 1; count < numTest; count++)
    {
        if (score[count] < lowest) 
            lowest = score[0];
    }
    

    The error is here:

    int lowest = score[count];
    

    It needs to be this:

    int lowest = score[0];
    

    Next, within the loop:

    lowest = score[0]; // ERROR
    

    Should be:

    lowest = score[count];
    

    So your loop should look like this:

    //Find lowest score.
    int lowest = score[0];
    for (count = 1; count < numTest; count++)
    {
        if (score[count] < lowest) 
            lowest = score[count];
    }
    

    Finally, the calculation of the total is also wrong. Subtract the lowest score after calculating the total of all scores, then divide by the number of scores less-one:

    //Calculate the total test scores.
    for (count = 0; count < numTest; count++)
    {
        total += score[count];
        total -= lowest; // ERROR: should not be here. should be AFTER the loop
    }
    

    Should be :

    for (count = 0; count < numTest; count++)
        total += score[count];
    total -= lowest; // note: NOT in the loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cool snippet of code that works well, except one thing. The
I have a problem with magic method __call The following code works well, except
This code seems to work well, modifying the properties of my button, except the
This code works well: UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:pickerFrame]; [pickerView addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
This code works well for displaying separate xml items in my main.xml. But is
I just realized that this piece of code works well in Firefox but not
I get a strange error and couldn't find the answer.. This code works well:
The code below works well right now; however, it's serially executed. I'd like to
The code below works well but grabs only the UIView which is VISIBLE on
I have this code that works well: {livre:empty_name} $.ajax({ url: sent.php, type: post, dataType:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.