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 7666503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:50:57+00:00 2026-05-31T14:50:57+00:00

I have to find the lowest input given, then average out the total minus

  • 0

I have to find the lowest input given, then average out the total minus the lowest score. I am having a bit of trouble with my averageScore function finding the lowest score from the array. I am getting very odd numbers as my output. Any suggestions on how to adjust this would be appreciated. Thanks in advance.

#include <iostream>
#include <cstdlib>
using namespace std;

//function prototypes
double* allocate(int&);
double averageScore(int&);

int main()
{   
    double* testArray;
        int numOfScores;
    double average;

    testArray = allocate(numOfScores);
    average = averageScore(numOfScores);

    //delete memory created
    delete[] testArray;

    return 0;
}

//function to collect user info, dynamically allocate
double* allocate(int &numOfScores)
{
    double* testArray;

    //prompt user for scores
    cout << "How many test scores would\n";
    cout << "you like to process: ";

    //user input validation 
    if(!(cin >> numOfScores))
    {
        cout << "Invalid input!\n";
        cout << "Program termination, please\n";
        cout << "restart the program." << endl;
        exit(0);
    }
    else if(numOfScores < 0)
    {
        cout << "Invalid input!\n";
        cout << "Program termination, please\n";
        cout << "restart the program." << endl;
        exit(0);
    }

    //dynammically allocate an arrray to hold the scores
    testArray = new double[numOfScores];

    //get the scores from user
    for (int count = 0; count < numOfScores; count++)   
    {
        cout << "Enter Score: ";

        //user input validation 
        if(!(cin >> testArray[count]))
        {
            cout << "Invalid input!\n";
            cout << "Program termination, please\n";
            cout << "restart the program." << endl;
            exit(0);
        }
        else if(testArray[count] < 0.0)
        {
            cout << "Invalid input!\n";
            cout << "Program termination, please\n";
            cout << "restart the program." << endl;
            exit(0);
        }


    }

    return testArray;
}

//function to calculate the average score
double averageScore(int &numOfScores)
{   
    double* testArray;

    double total,
           average,
           scores[0],
           lowest;

    lowest = scores[0];   

    //calculate total scores entered
    for(int count = 0; count < numOfScores; count++)
    {
        total += testArray[count];

        //find lowest score entered 
        for(int count = 1; count < numOfScores; count++)
        {
            if (testArray[numOfScores] < lowest)
                lowest = scores[numOfScores];
        }
    }

    //average the total amount of scores drop the lowest
    average = (total -  lowest) / numOfScores;

    cout << "The average test score is: " << average << endl;
    cout << "Lowest is: " << lowest << endl;

    return average;
}
  • 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-05-31T14:50:58+00:00Added an answer on May 31, 2026 at 2:50 pm

    There are a lot of problems with your averageScore function, but i’ll cover the most basic one for now.

    First off, you should pass it some sort of data. Right now you’re using testArray I don’t even see where it is allocated. I’m surprised that you’re not getting segmentation faults when you run this.

    But it’s also not initialized. In c++, when you declare a pointer, the variable it points to has a value. It has a garbage value, and if you perform arithmetic operations with that garbage value, then your output will be garbage too.

    You have to make your list of scores available to your averageScore function, preferably by passing them in as a parameter.

    the beginning of your averaging function looks like the following:

    double averageScore(int &numOfScores)
    {   
        double* testArray;
        ...
    

    instead it should look like this

    double averageScore(double*testArray, int numOfScores)
    {   
        ...
    

    when you use &numOfScores instead of numOfScores, that means that if you change numOfScores in your averageScore function, than it will change in your main function as well, and you shouldn’t do that.

    now, on the double* testArray; line, you’re declaring a brand new pointer, named “testArray”, and there’s no meaningful data in it, although it might be full of garbage. there might be other double pointer variables, named “testArray” in your code, but none of them are in the scope of your averageScore function. If you pass testArray in, in your method call, you’ll then be able to use it. for example: double someNumber = testArray[i].

    Bare in mind that your array is also being passed by reference. If you would rather pass it by value, you can try

    `double averageScore(double testArray[], int numOfScores)`
    

    but don’t quote me on that one

    Once you’ve done that, your code will still have some issues, but the output should be meaningful enough that you’ll hopefully be able to work those out on your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble with an SQL statement that have to find the number
I am given an input, N, i have to find the number of list
I have two Java instances of java.util.Date and I have to find out if
I am working on a project where I have to find out the keyword
I have to find the lowest possible sum from numbers' difference. Let's say I
I am evaluating datamining packages. I have find these two so far: RapidMiner Weka
I have a Find function in order to find an element from a BST
I have to find some patters from a XML file, but i am unable
I have an xml file in which I have to find patterns and put
I want to apply NTFS-Search to our project. Our project have to find the

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.