title: Problems creating matrices from user input in C++
body: <p>I'm trying to just make a simple program where the user inputs every value of a matrix, then the program prints the matrix. So far I have </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  int main()
  {
      int n;
      cout &lt;&lt; "A is an nxn matrix.\nn=";
      cin &gt;&gt; n;
      int matrix[n-1][n-1];
      for (int i=0;i&lt;n;i++)
      {
          for (int j=0;j&lt;n;j++)
          {
              cout &lt;&lt; "A[" &lt;&lt; i+1 &lt;&lt; "][" &lt;&lt; j+1 &lt;&lt; "]=";
              cin &gt;&gt; matrix[i][j];
          }
      }
      cout &lt;&lt; "[[ ";
      for (int i=0;i&lt;n;i++)
      {
          for (int j=0;j&lt;n;j++)
          {
              cout &lt;&lt; matrix[i][j] &lt;&lt; " ";
          }
          if (i!=n-1) //Just to make the output pretty
              cout &lt;&lt; "]\n [ ";
          else
              cout &lt;&lt; "]]";
      }
  }
  </code></pre>
  
  <p>`</p>
  
  <p>However, whenever I put in a matrix of any size, for instance [[1,2,3][4,5,6][7,8,9]], the program returns [[1,2,4][4,5,7][7,8,9]].</p>
  
  <p>Can anyone tell me why this is happening and how to fix it?</p>