<p>I would assume that you meant <strong>normal</strong> magic square (where the number are restricted to 1,2..n^2)</p>

<p>First of all, it's impposible to construct such magic square for n=2.</p>

<p>2nd, you would need an whole new algorithm for it, which is much more complicated. The problem (constructing magic square for <strong>any</strong> even number) is solved <a href="https://arxiv.org/ftp/arxiv/papers/1202/1202.0948.pdf" rel="nofollow noreferrer">in this paper</a> and while there isn't any psaudo code there, the implementation from the explenation is quite straightforward (long one though).</p>
Finalize the magic square generator
<p>This code that runs only for odd N. The problem is that there are no ideas how to add support for even values N</p>

<pre><code>#include "stdafx.h"
#include &lt;iostream&gt;

using namespace std;

int main()
{
    setlocale(0, "");
    int n;
    cout &lt;&lt; "Enter the size of the magic square - ";
    cin &gt;&gt; n;

    int **matrix = new int *[n];
    for (int i = 0; i &lt; n; ++i)
    {
        matrix[i] = new int[n];
    }

    int nsqr = n * n;
    int i = 0, j = n / 2;

    for (int k = 1; k &lt;= nsqr; ++k)
    {
        matrix[i][j] = k;
        i--;
        j++;
        if (k % n == 0)
        {
            i += 2;
            --j;
        }
        else
        {
            if (j == n)
            {
                j -= n;
            }
            else if (i &lt; 0)
            {
                i += n;
            }
        }
    }

    cout &lt;&lt; "\n\nMagic square size - " &lt;&lt; n &lt;&lt; "\n\n";
    for (int i = 0; i &lt; n; i++)
    {
        for (int j = 0; j &lt; n; j++)
        {
            cout &lt;&lt; matrix[i][j] &lt;&lt; "\t";
        }
        cout &lt;&lt; endl;
    }

    for (i = 0; i &lt; n; i++)
        delete[] matrix[i];
    delete[] matrix;

    system("pause &gt;&gt; null");
    return 0;
}
</code></pre>

<p>I would be grateful for tips on troubleshooting.</p>

<p>If i'm not mistaken, the problem is in this line: </p>

<pre><code>int i = 0, j = n / 2;
</code></pre>

<p>But i don't know how to change the code to support even values</p>