I have been working on my code today and have minimalized my errors. Sadly, I still have a few errors left I can't figure out how to solve.

28 F:\Program6-Arrays2.8.cpp cannot convert `double' to `double*' for argument `1' to `double getInput(double*, int)'
#include<iostream>
#include<cmath>
#include<conio.h>
#include<iomanip> //needed for setw()

using namespace std;

// Function prototypes
double getInput(double[],int);
double getLow(double[],int);
double getHigh(double[],int);
double getsum(double[],int);


int main()
{
    const int SIZE=8;
    int num;
    double numbers;
    double sum;
    double lowestscore;
    double highestscore;
    double scores[SIZE];
    double array[0];

cout << setprecision(1) << fixed << showpoint;

sum= getInput(numbers,SIZE);

lowestscore = getLow (array,SIZE);

highestscore = getHigh (array,SIZE);

sum = getsum (array,SIZE);

sum -= lowestscore;

sum -= highestscore;
    

cout << "Contestant Receives: " << sum << endl;

cout << "Dropped Low Score: " << lowestscore << endl;

cout << "Dropped High Score: " << highestscore << endl;

return 0;
    
    
}

double getInput(double numbers[],int size)
{
     int index;
     
     for(index = 0; index <= size - 1;index++)
     {
 
  cout << "Enter Judges Score #" << (index+1) << ":";
  cin >> numbers[index];
}
}

double getLow(double array[], int size)
{
       double lowest;
       int counter=1;
       lowest = array[0];
       
for(int counter = 1; counter < size ; counter++)
{
        if( array [counter] < lowest)
            lowest = array [counter];

return lowest;
}

    
    
double getHigh( double array[] , int size);
{
    double highest;
    
    highest = array[0];
    for(int counter = 1; counter < size ; counter++)
{
    if(array [counter] > highest)
    highest = array [counter];
    
    return highest;
}

double getsum(double array[],int size);
{
       double sum=0;
       for(int count = 0 ;count < size ;count++)
       sum += array [count];

       
       return sum;
}
}
}

Dani AI

Generated

The error pointed out (passing a scalar when the function expects a collection) is the root cause. is correct that you can overload, but you do not need to — simpler is to make your function signatures match what you actually pass, and to fix a few other common mistakes visible in the thread: declaring an array of size zero, using the wrong variable when calling functions, stray semicolons after function headers, returning inside a loop, and shadowing loop variables.

Fix plan (short):

  • Create a real container for the scores (fixed array or, better, std::vector) and pass that container to your functions.
  • Make each function signature match its definition (no extra semicolons) and place the return after loops, not inside them.
  • Either have read/getInput fill the container and return void, or have it return a computed value (sum) — but keep the contract clear and consistent.
  • Use std::min_element, std::max_element, and std::accumulate rather than writing those loops by hand, at least while learning.

Example approach (using std::vector):

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

void readScores(std::vector<double>& v) {
  for (size_t i = 0; i < v.size(); ++i) {
    std::cout << "Score #" << (i+1) << ": ";
    std::cin >> v[i];
  }
}

double totalExcludingExtremes(const std::vector<double>& v) {
  double sum = std::accumulate(v.begin(), v.end(), 0.0);
  double lo  = *std::min_element(v.begin(), v.end());
  double hi  = *std::max_element(v.begin(), v.end());
  return sum - lo - hi;
}

Troubleshooting tips: compile with warnings enabled (g++ -Wall -Wextra), inspect mismatched prototype/definition pairs, remove stray semicolons after function headers, and avoid declaring useless arrays like array[0]. For reference on containers and algorithms see std::vector and std::accumulate / min_element / max_element.

Recommended Answers

All 4 Replies

you have the function double getInput(double[],int); to accept a double array; however, in line #28 you are attempting to pass in a double var.

one solution could be to overload the getInput() function so you would have a version of the function that would accept a double, and one version that would accept a double array.

you have the function double getInput(double[],int); to accept a double array; however, in line #28 you are attempting to pass in a double var.

one solution could be to overload the getInput() function so you would have a version of the function that would accept a double, and one version that would accept a double array.

Is it possible to convert a double variable into a double array?

you have the function double getInput(double[],int); to accept a double array; however, in line #28 you are attempting to pass in a double var.

one solution could be to overload the getInput() function so you would have a version of the function that would accept a double, and one version that would accept a double array.

How would I overload the getInput()function?

How would I overload the getInput()function?

You overload a function by making different versions of it. All the versions have the same name, they just differ in the parameters. For example:

int getInput(a[], int);
int getInput(int, int);
int getInput(double, float);

Then the compiler will automatically select the right version for what you are trying to do so that you don't have to worry about getting the parameters right (so long as you have a version to cover it).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.