Hey folks, I am having problems with sumMajorDiagonal function. I am suppose to create that function so that the program adds the fist diagonal of the matrix, but my function its not delivering that result.
#include <iostream>
using namespace std;
const int SIZE = 4;
double sumMajorDiagonal(const double m[][SIZE], int row, int column, /*int i, int j*/) { //create a function that sums the first diagonal in a matrix
double sumDiagonal = 0;
// Loop to sum main diagonal
for (int i = 0; i<row; i++)
{
for (int j = 0; j<column; j++)
{
if (i == j)
sumDiagonal = sumDiagonal + [i][j];
}
}
return sumDiagonal;
}
int main() {
const int columns = 4;
const int rows = 4;
int columnIndex = 0;
cout << "Enter a 4-by-4 matrix row by row : " <<endl; //ask user value input
for (i = 0; i < 4; i++) {
for (j = 0; j, 4; j++) {
cin >> myArr[columns][rows];
}
}
cout << "\nSum of main diagonal elements is " /*<< sumDiagonal*/;
return 0;
}