Need help with 2D array input

Hello all, I've been stuck on this problem for sometime. Originally I have create 2x3 2D array where the values are entered by the user then print them out. Also I have to print the sum of each column. I've gotten examples of how input works with arrays but don't understand it still. The code below is an example from our book in class, but only displays 2D arrays with given values, which I've been trying to work off of and modify.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream> 
#include <array> 
using namespace std; 
 
const size_t rows = 2; 
const size_t columns = 3; 
void printArray( const array< array< int, columns >, rows> & ); 
 
int main() 
{ 
 array< array< int, columns >, rows > array1 = { 1, 2, 3, 4, 5, 6 }; 
 array< array< int, columns >, rows > array2 = { 1, 2, 3, 4, 5 }; 
 
 cout << "Values in array1 by row are:" << endl; 
 printArray( array1 ); 
 
 cout << "\nValues in array2 by row are:" << endl; 
 printArray( array2 ); 
} // end main 
 
// output array with two rows and three columns, using nested for loops, one for rows, 
one for columns 
void printArray( const array< array< int, columns >, rows> & a ) 
{ 
 // loop through array's rows 
 for ( size_t row = 0; row < a.size(); ++row ) 
{ 
 for ( size_t column = 0; column < a[ row ].size(); ++column ) 
 cout << a[ row ][ column ] << ' '; 
 cout << endl; 
} // end outer for 
 
 
} // end function printArray 
For input, all you really need to do is the reverse of the output operation in the inner for loop:
1
2
3
int val;
cin >> val;
a[row][column] = val;
Topic archived. No new replies allowed.