title: c++ - Output a 2D array and the sum of its elements
body: <p>In this program I'm trying to add the elements of a 2d array, print the entire array, and print its sum using functions. I know I am very close, but when I try to print the sum it isn't working. Here is my code.</p>
  
  <pre><code>void DisplayB(int b[][4], int col, int row, int total);
  
  
  int main()
  {
      int total = 0;
  
      int b[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
  
      DisplayB(b, 3, 4, total);
  
  
  }
  
  void DisplayB(int b[][4], int col, int row, int total)
  {
      total = 0;
      cout &lt;&lt; "Array c using the display function: " &lt;&lt; endl;
      for (int i = 0; i&lt;col; i++)   
      {
          for (int j = 0; j&lt;row; j++) 
          {
              cout &lt;&lt; b[i][j] &lt;&lt; "  ";
  
              total+=b[i][j];
          }
              cout&lt;&lt;total;
              cout &lt;&lt; endl;
  
      }
  
  }
  </code></pre>
  
  <p>When I run this in the compiler I end up getting this:</p>
  
  <pre><code>1 2 3 4 10
  5 6 7 8 36
  9 10 11 12 78
  </code></pre>
  
  <p>It looks like what's happening is it finds the sum of the each row and adds it to the sum of the prior row. Any ideas?</p>