title: Dyanamic 2d array in C++ using double pointer
body: <p>I have the following code, I made sure I did everything as explained in <a href="https://stackoverflow.com/questions/16001803/pointer-to-pointer-dynamic-two-dimensional-array">Pointer-to-pointer dynamic two-dimensional array</a></p>
  
  <p>I need my 2d matrix to be dyanmic i.e the user needs to enter the dimensions. But I am getting error in my cin when taking the input form the user. whats wrong with the following code?  </p>
  
  <pre><code>int numberOfRows, numberOfColumn;
  cout &lt;&lt; "Please enter the number of rows: ";
  cin &gt;&gt; numberOfRows;
  cout &lt;&lt; endl &lt;&lt; "Please enter the number of columns ";
  cin &gt;&gt; numberOfColumn;
  
  
  int** matrix= new int*[numberOfRows];
  
  for (int i=0; i&lt;numberOfRows; i++)
  {
      matrix[numberOfRows]= new int[numberOfColumn];
  }
  
  for (int i=0; i&lt;numberOfRows; i++)
  {
      for(int j=0; j&lt;numberOfColumn; j++)
      {
          cout &lt;&lt; "Please enter Row " &lt;&lt; (i+1) &lt;&lt; " Column "&lt;&lt; (j+1) &lt;&lt;" element: ";
          cin&gt;&gt; matrix[i][j];
          cout &lt;&lt; endl;
      }
  }
  
  for (int i=0; i&lt;numberOfRows; i++)
  {
  
      for(int j=0; j&lt;numberOfColumn; j++)
      {
          cout &lt;&lt; matrix[i][j];
      }
  }
  </code></pre>