Hello all,

I am having a problem with a c++ assignment. The basic problem is that I have two functions -- one to compute the mean and and one to compute the variance of a subarray from a main array -- arraym.I keep getting an extra parameter in call error when I try to compile. Here are my functions:

``````//mean function
double mean(int arraym[299][299], int minl, int minw, int rlm, int rwm)
{
double sum(0);
int n(0);
for (int x=minl; x<=rlm; x++)
{
for (int y=minw; y<=rwm; y++)
{
sum += arraym[x][y];
n++;
}
}
return sum/n;
}

//variance function
double variance(int arraym[299][299], int minl, int minw, int rlm, int rwm)
{
double sum(0), me;
int n(0);
me = mean(arraym, minl, minw, rlm, rwm);
for (int x=minl; x<=rlm; x++)
{
for (int y=minw; y<=rwm; y++)
{
sum += (arraym[x][y] - me)*(arraym[x][y] - me);
n++;
}
}
return sum/(n-1);
}``````

and here is my function call:

``````double y;
y = variance(arraym[299][299], minl, minw, rlm, rwm);``````

any ideas why I would be getting this error? minl and minw are the starting sub-array offsets and rlm and rwm are the ending sub-array offsets. Everything else is declared correctly elsewhere in my code.

You just need to change

``variance(arraym[299][299], minl, minw, rlm, rwm);``

to

``variance(arraym, minl, minw, rlm, rwm);``

This compiles for me:

``````#include <cstdlib>
#include <iostream>
#include <string>

//mean function
double mean(int arraym[299][299], int minl, int minw, int rlm, int rwm)
{
double sum(0);
int n(0);
for (int x=minl; x<=rlm; x++)
{
for (int y=minw; y<=rwm; y++)
{
sum += arraym[x][y];
n++;
}
}
return sum/n;
}

//variance function
double variance(int arraym[299][299], int minl, int minw, int rlm, int rwm)
{
double sum(0), me;
int n(0);
me = mean(arraym, minl, minw, rlm, rwm);
for (int x=minl; x<=rlm; x++)
{
for (int y=minw; y<=rwm; y++)
{
sum += (arraym[x][y] - me)*(arraym[x][y] - me);
n++;
}
}
return sum/(n-1);
}

int main(int argc, char *argv[])
{
int arraym[299][299];
int minl, minw, rlm, rwm;
double y = variance(arraym, minl, minw, rlm, rwm);
return 0;
}``````

thanks a bunch. I had been trying that unsuccessfully but had my mean and variance functions defined after my main code instead of before. I didn`t realize that would make a difference but when I moved them to before the main function it compiled successfully

You can also put

``double mean(int arraym[299][299], int minl, int minw, int rlm, int rwm);``

(note the addition of the semicolon at the end)

before main, then exactly the same thing you had before after main:

``````double mean(int arraym[299][299], int minl, int minw, int rlm, int rwm)
{
double sum(0);
int n(0);
for (int x=minl; x<=rlm; x++)
{
for (int y=minw; y<=rwm; y++)
{
sum += arraym[x][y];
n++;
}
}
return sum/n;
}``````
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.