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
Sorry about the length of it.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); }



LinkBack URL
About LinkBacks


