2d array with random numbers program

Hi all,

I was wondering if I could have some help with logic for the following program prompt:

2) Please write a program that creates a 6 x 6 array where the first element in each row is a random number between -5 and +5 and every subsequent element in the row is equal to the previous number in the row plus 3. A different set of values should be displayed every time the program runs. Display the array on the screen neatly formatted (so that it appears as a 6 x 6 array). An example output from the program would be as shown below. Notice the first column has random integers between -5 and +5 and each subsequent column is the previous column adding 3 to each value.

-3 0 3 6 9 12
-1 2 5 8 11 14
-4 -1 2 5 8 11
5 8 11 14 17 20
5 8 11 14 17 20
2 5 8 11 14 17


This is for practice but I'd really love some help with logic and use of random numbers for this program. Thank you
To give you an idea.

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 <random>

int randomNumber(int, int);

int main()
{
	const int rows{ 6 };
	const int cols{ 7 };
	int arrNums[rows][cols]{};

	for (int countRow = 0; countRow < rows; countRow++)
	{
		// Input a random number in each row. The column will be zero.
		arrNums[countRow][0] = randomNumber(-5, 5); 

		for (int countCol = 1; countCol < cols; countCol++)
		{
			arrNums[countRow][countCol] = arrNums[countRow][countCol - 1] + 3;
			std::cout << arrNums[countRow][countCol] << '\t';
		}
		std::cout << std::endl;
	}
	return 0;
}

int randomNumber(int min, int max)
{
	std::mt19937 generator(std::random_device{}());
	std::uniform_int_distribution<int> distributionToss(min, max); // Set the numbers for int.
	const int randNumber = distributionToss(generator);

	return randNumber;
}


Output:

7       10      13      16      19      22
-2      1       4       7       10      13
5       8       11      14      17      20
8       11      14      17      20      23
3       6       9       12      15      18
0       3       6       9       12      15

Topic archived. No new replies allowed.