I am trying to get my program to print the normalized matrix values and the maximums for each column. The output should be organized nicely in rows by columns manner followed by a row of values for each column maximum. For each column of the matrix find the member-cell with maximum value. Divides all the members of that column with the value of that cell. What am I doing wrong here? I am stuck.

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

void DivideArray(int[6][5],int[6][5],int,int);

int main()
{
	int theMatrix[6][5]; 
	double a[6][5] = {{1.267, 0.167, 0.250, 2.670, 1.000},
	{3.240, 0.376, 0.375, 3.400, 1.128},
	{7.564, 0.668, 0.500, 4.303, 1.270},
	{5.041, 1.043, 0.625, 5.313, 1.410},
	{4.660, 1.502, 0.750, 7.650, 1.693},
	{5.727, 2.044, 0.875, 3.600, 2.257}};

    cout << "Array: " << endl;
    for (int i = 0; i < 6; i++)
	{
		for (int j=0; j < 5; j++)
		{
        cout << "array [" << i << "][ "<< j <<"] = " << a[i][j] <<"   ";
		}
		cout << endl;
		}
	
	Void DivideArray(int table[6][5], int theMatrix[6][5], int, int,)
	{ 	
		for (int i=0; i < 6; i++) 		
			for (int j=0; j < 5; j++) 			
				theMatrix[6][5]= table[5][6] / table[6][5]; 
	}
    return 0;
}

You can't define a function inside another function. Here is one way :

#include <iostream>
void aFunction(int x, int y); //function prototype
int main(){
  aFunction(2,2); //function call
}//end of main
void aFunction(int x, int y){ //function header and definition
 cout << "(" << x << "," << y << ")" << endl;
}

You see, in the above code, the function definition is outside in its own
space, and not defined inside main.

Hmm, the divide array function is never called from main. It also return a value even though it is declared as Void. There are other issues causing the program to not compile, like a comma with nothing after it. I suggest you go through remove code (or comment it out) until the program compiles, then slowly add code, compiling often to make sure there are no syntax errors. I'll check back later to see if you have posted code that compiles.

Ah, I see you just got the bracket in the wrong place. There is also a comma after int that should not be there. Here it is cleaned up:

//...
    cout << endl;
    }
    return 0;
}

void DivideArray(int table[6][5], int theMatrix[6][5], int, int)
{ 
  for (int i=0; i < 6; i++) 
      for (int j=0; j < 5; j++) 
         theMatrix[6][5]= table[5][6] / table[6][5]; 
}

Now you should call DivideArray from inside your main function.

Ah, I see you just got the bracket in the wrong place. There is also a comma after int that should not be there. Here it is cleaned up:

//...
    cout << endl;
    }
    return 0;
}

void DivideArray(int table[6][5], int theMatrix[6][5], int, int)  <-----
{ 
  for (int i=0; i < 6; i++) 
      for (int j=0; j < 5; j++) 
         theMatrix[6][5]= table[5][6] / table[6][5]; 
}

Now you should call DivideArray from inside your main function.

Within the definition of DivideArray (it is not necessary for the prototype up top) you need to name those two int parameters (see the line I marked with an arrow) or else there will be an error.

This article has been dead for over six months. Start a new discussion instead.