# Thread: help with 1 function

1. ## help with 1 function

Hello. I am having trouble with this program that I wrote. Just one function is giving me a problem, the error that I get is:binary '=' : no operator defined which takes a right-hand operand, you get the idea. Code posted below. The fuction that is giving me problems is FindLargest, but as you can see I set IndexOfLargest = (FindLargest, IntVec) See Below.
Thanks
Code:
```#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;

double CreateVec(vector <int> &);
void PrintVec(vector <int>);
int FindLargest(vector <int>, int);
double Average (vector <int>);
vector <int> Exchange(vector <int>, const int);
void FillAryVectors(vector <double> [], double);
void PrintAryVectors(vector <double> []);

int main (void)
{
double Avg;
int IndexOfLargest;
vector <int> IntVec (100);
vector <double> DbArrayVec [10];

srand(time(NULL));

Avg = CreateVec (IntVec);

PrintVec (IntVec);

cout << "The average is " << setiosflags(ios::fixed) << setprecision(2) <<
Average (IntVec) << endl << endl;

IndexOfLargest = (FindLargest, IntVec);

Exchange (IntVec, IndexOfLargest);

FillAryVectors (DbArrayVec, 0.5);

PrintAryVectors (DbArrayVec);

return 0;
}

double CreateVec(vector <int> & ivec)
{
int total = 0;
int size;

vector <int> MyVec (100);

if (ivec.size() != 0)
{
MyVec = ivec;
size = ivec.size();
}
else
size = 100;

for (int i = 0; i < size; i++)
{
MyVec[i] = rand() & 199 - 99;
total += MyVec[i];
}
ivec = MyVec;

return (double(total)) / ivec.size();
}

void PrintVec (vector <int> ivec)
{
for (int index = 0; index < ivec.size(); index++)
{
cout << setw(5) << ivec[index];

if (index % 10 == 9)
cout << endl;
}

cout << endl;
}

void FillAryVectors(vector <double> aryv[10], double value)
{
vector <double> TempVec (10, value);

for (int i = 0; i < 10; i++)
aryv[i] = TempVec;
}

void PrintAryVectors (vector <double> aryv[10])
{
for (int row = 0; row < 10; row++)
{
for (int col = 0; col < 10; col++)
cout << setiosflags(ios::fixed) << setprecision(2) << setw(5) << aryv[row][col];
cout << endl;
}
}

double Average (vector <int> ivec)
{
int sum = 0;
int size = ivec.size();

for (int index = 0; index < size; index++)
sum += ivec [index];

return (double (sum) / size);
}
int FindLargest(vector <int> ivec, int sizeX)
{
int counter;
int maxIndex = 0;

for (counter = 1; counter < sizeX; counter++)
if (ivec[maxIndex] < ivec[counter])
maxIndex = counter;

return maxIndex;
}
vector <int> Exchange(vector <int> ivec, const int cnt)
{
for (int i = 0; i < cnt; i++)
ivec [i] *= 2;

return (ivec);
}```
Sorry about the length of it.

2. made IndexOfLargest = (FindLargest, IntVec);

IndexOfLargest = (FindLargest, 100);

100 is the size it was declared too, hope it fixes it, no errors anyway.

Code:
```#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;

double CreateVec(vector <int> &);
void PrintVec(vector <int> );
int FindLargest(vector <int>, int);
double Average (vector <int> );
vector <int> Exchange(vector <int>, const int);
void FillAryVectors(vector <double> [], double);
void PrintAryVectors(vector <double> []);

int main (void)
{
double Avg;
int IndexOfLargest;
vector <int> IntVec (100);
vector <double> DbArrayVec [10];

srand(time(NULL));

Avg = CreateVec (IntVec);

PrintVec (IntVec);

cout << "The average is " << setiosflags(ios::fixed) << setprecision(2) <<
Average (IntVec) << endl << endl;

IndexOfLargest = (FindLargest, 100);

Exchange (IntVec, IndexOfLargest);

FillAryVectors (DbArrayVec, 0.5);

PrintAryVectors (DbArrayVec);

return 0;
}

double CreateVec(vector <int> & ivec)
{
int total = 0;
int size;

vector <int> MyVec (100);

if (ivec.size() != 0)
{
MyVec = ivec;
size = ivec.size();
}
else
size = 100;

for (int i = 0; i < size; i++)
{
MyVec[i] = rand() & 199 - 99;
total += MyVec[i];
}
ivec = MyVec;

return (double(total)) / ivec.size();
}

void PrintVec (vector <int> ivec)
{
for (int index = 0; index < ivec.size(); index++)
{
cout << setw(5) << ivec[index];

if (index % 10 == 9)
cout << endl;
}

cout << endl;
}

void FillAryVectors(vector <double> aryv[10], double value)
{
vector <double> TempVec (10, value);

for (int i = 0; i < 10; i++)
aryv[i] = TempVec;
}

void PrintAryVectors (vector <double> aryv[10])
{
for (int row = 0; row < 10; row++)
{
for (int col = 0; col < 10; col++)
cout << setiosflags(ios::fixed) << setprecision(2) << setw(5) << aryv[row][col];
cout << endl;
}
}

double Average (vector <int> ivec)
{
int sum = 0;
int size = ivec.size();

for (int index = 0; index < size; index++)
sum += ivec [index];

return (double (sum) / size);
}
int FindLargest(vector <int> ivec, int sizeX)
{
int counter;
int maxIndex = 0;

for (counter = 1; counter < sizeX; counter++)
if (ivec[maxIndex] < ivec[counter])
maxIndex = counter;

return maxIndex;
}
vector <int> Exchange(vector <int> ivec, const int cnt)
{
for (int i = 0; i < cnt; i++)
ivec [i] *= 2;

return (ivec);
}```

3. Ok, I fixed that. Now when I run the program it prints out a 10x10 vector, then tells me the average. but after the average it has 0.50 in a 10x 10 vector I need the floating point value to initialize the elements which should be passed as a parameter, any ideas on how to do this? And also my FindLargest function isn't working. Or at least it isn't printing out the largest element in the integer vector like I intended to. Thanks for the help.
K