So I'm starting my magic square hw, where I ask the user to enter a odd integer, and it will create a magic square off that. I have to use pointers and arrays as that is all I have learned so far. Not asking how to do the magic square, but what is causing a segmentation fault, im probably not doing pointers to 2d arrays correctly
#include <iostream>
using namespace std;
int main()
{
int **ptr;
int odd;
do
{
cout << "Enter a odd number to create a magic square: ";
cin >> odd;
}while(odd % 2 != 1);
ptr = new int *[odd]; //creates a new array of pointers to int objects
for(int i = 0; i < odd; i++)
ptr[i] = new int[odd];
//set it all to 0
for(int i = 0; i < odd; i++)
{
for (int j = 0; j < odd; j++)
{
ptr[i][j] = 0;
cout << ptr[i][j];
}
}
int row = odd;
int column = odd / 2;
int lastrow = row;
int lastcolumn = column;
//begin adding numbers to magic square
ptr[row][column] = 1;
for (int i = 2; i < odd * odd; i++)
{
}
//delete
for(int i = 0 ; i < odd; i++)
delete [] ptr[i];
delete [] ptr;
return 0;
}