int game()
{
int n;
cout << "enter an odd number: ";
cin >> n;
int MagicSquare[n][n]; // It says that the expression must have a constant type?
int newRow,newCol;
int i = 0;
int j = n / 2;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
MagicSquare[i][j] = 0;
}
}
for (int value = 1; value <= n*n; value++)
{
MagicSquare[i][j] = value;
newRow = (i + 1) % n;
newCol = (j + 1) % n;
if (MagicSquare[newRow][newCol] == 0)
{
i = newRow;
j = newCol;
}
else
{
i = (i - 1 + n) % n;
}
}
for (int x = 0; x<n; x++)
{
for (int y = 0; y<n; y++)
cout << MagicSquare[x][y] << " "<<endl;
}
}
daniela.valkanova 0 Newbie Poster
Learner010 99 Posting Whiz in Training
Gonbe 32 Newbie Poster
Learner010 99 Posting Whiz in Training
tinstaafl 1,176 Posting Maven
Learner010 99 Posting Whiz in Training
tinstaafl 1,176 Posting Maven
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.