0

Hello everyone,

I have been trying to get this code to work, but so far all it does is tell me :

Input the order of the Matrix(Keep it Odd):3

1.11286e-307

1

0

1.11341e-308

1.11286e-307

0

0

1.11343e-308

1.11286e-307

0

0

1.11342e-308

Press any key to continue . . .

I am supposed to create a magic square for any odd number order that anyone puts in. Put in a 3 and get a 3x3 magic square. And it MUST be done using pointers. This is what I have so far:

```
#include <iostream>
using namespace std;
void main(){
int n,i,j;
int m=1;
cout<<"Input the order of the Matrix(Keep it Odd):";
cin>>n;
double **ms;
//allocated the space for the rows and the inputs for each row
ms=new double*[n];
for(i=0;i<n;i++)
ms[i]=new double[n];
//trying to populate the magic square
for(i=0;i<n;i++)
for(j=0;j<n;j++)
ms[i][j]=m;
m++;
if (ms[(i+n-1)%n][(j+n+1)%n])
i = (i+n+1)%n ;
else
i = (i+n-1)%n , j = (j+n+1)%n ;
//print the magic square
for(i=0;i<=n;i++){
for(j=0;j<=n;j++)
cout<<ms[i][j]<<" "<<endl;
}
//deallocate the space
for(i=0;i<=n;i++)
delete [] ms[i];
delete []ms;
}
```

Could someone please tell me why it wont let me populate it to create the magic square with 1 in the middle of the first row and so on?