Im having issues with my class assigment. I have a mac and not a PC so I can only compile when Im at school.
This is the assignment:
Write a test program that reads a 4-by-4 matrix and displays the sum of all its elements. Heres a sample run:
Heres the code I have but its not doing what I want it to do.
- Code: Select all
#include <iostream>
using namespace std;
const int COLUMN_SIZE = 4;
int sum(const int a[] [COLUMN_SIZE], int rowSize)
{
int total = 0;
for (int row = 0; row < rowSize; row++)
{
for (int column = 0; column < COLUMN_SIZE; column++)
{
total += a[row][column];
}
}
return total;
}
int main()
{
int m[4][4]=
{
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}
};
cout<< "Sum of the matrix"<< sum(m,4) << endl;
return 0;
}
Its only displaying the matrix and not asking what to input. Assingment is late so any help would be great! Thanks man!
Nick
