2-D arrays

How would I go about creating a 2x3 2-D array with user input. In my book shows an example with the arrays already defined and I understand the example. I don't know how to go about putting in user input. Here is the book code.



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
#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);
}


void printArray(const array< array< int, columns >, rows> & a)
{
	for (auto const &row : a)
	{
		for (auto const &element : row)
			cout << element << ' ';
		
		cout << endl;
	}
}

Here is a very basic example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <string>
using namespace std;

int main(){

int arr1[2][3];

for(int i = 0;i<2;i++){
for(int x = 0;x<3;x++){

cin >> arr1[i][x];

}}
    return 0;
}


Basically, you declare 2 for loops instead of 1. Hope this helps!
Topic archived. No new replies allowed.