For those unfamiliar with the classic magic square algorithm: A magic square is a two dimensional array (n x n) which contains a numerical value between the values 1 and n^2
You forgot to initialize your MagicSquare to contain all zeros:
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
MagicSquare[i][j] = 0;
}
}
Thus this check will almost always fail:
if ( MagicSquare[newRow][newCol] == 0 ) {
i = newRow;
j = newCol;
}
As C/++ doesn't initialize them to 0 for you.