I have a set of values stored in a 2d matrix. I want to create separate totals for the values which have the same first index. Here's a short example:
typedef int matrix [9][9];
matrix sampleMatrix;
sampleMatrix [1][2] = 3;
sampleMatrix [1][4] = 5;
sampleMatrix [3][5] = 6;
sampleMatrix [3][2] = 2;
sampleMatrix [5][1] = 1;
for (int i = 0; i < 9; i++){
for (int j = 0; j < 9; j++){
//here's where I'm stuck
//if i = 1, then total all values with i = 1 etc.
if(sampleMatrix[i]){
int sum = sum + sampleMatrix[i][j];
}
std::cout << i << " Total: " << sum << std::endl;
}
}
Thanks for any help.