Im trying to diagonally sum the numbers in a 2D array(8 X 8), and for some reason, I am only able to display the diagonal numbers, and not add them up....lol

#include <iostream> using namespace std; int main() { int twoDimArray[8][8]; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { twoDimArray[i][j] = (i + 1) * (j + 1); } } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { cout << twoDimArray[i][j] <<" "; } cout << endl; } for(int i = 0;i < 8;i++) { int sum = 0; sum += twoDimArray[i][i]; // I believe the problem is here... cout << sum << endl; } return 0; }

Any help would be nice....Thanks in advance.

----------------

Now playing: Matisyahu - Time Of Your Song

via FoxyTunes