Copying 1d arrays into a 2d array

I'm having trouble doing this function for my code. Every time I copy an array into a 2d array instead of outputting all the values it only outputs the same value 4 times. For the alpha array, I input 20 numbers and for beta, I double the numbers from alpha.

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
  void inputArray(int alpha[])
{
	int i;
	cout << "Enter 20 integers" << endl;
	for (i = 0; i < 20; i++)
	{
		cin >> alpha[i];
	}
	cout << "Alpha after reading 20 numbers" << endl;
	for (i = 0; i < 20; i++)
	{
		cout << alpha[i] << " ";
	}
	cout << endl; 
}

double doubleArray(int beta[], int alpha[])
{
	int i; 
	for (i = 0; i < 20; i++)
	{
		beta[i] = alpha[i] * 2;
	}
	cout << "Beta after a call to doubleArray" << endl;
	for (i = 0; i < 20; i++)
	{
		cout << beta[i] << " ";
	}
	cout << endl; 

	return beta[20];
}



Write the definition of the function copyAlphaBeta that stores alpha
into the first five rows of inStock and beta into the last five rows of
inStock. Make sure that you prevent the function from modifying the
elements of alpha and beta.
And this the function I have a problem with.
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
  void copyAlphaBeta(int inStock[][4], int alpha[], int beta[])
{
	int i, j; 
	for (i = 0; i < 10; i++)
	{
		for (j = 0; j < 4; j++)
		{
			if (i < 5)
			{
				inStock[i][j] = alpha[j];
			}

			else if (i > 5)
			{
				inStock[i][j] = beta[j];
			}
		}
	}
	cout << "inStock after call to copyAlphaBeta" << endl;
	

	for (i = 0; i < 10; i++)
	{
		for (j = 0; j < 4; j++)
		{
			cout << inStock[i][j] << " ";
		}
		cout << endl;
	}
	
}


Can anyone help?
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <algorithm>
#include <iterator>

constexpr auto SIZE = 5;
constexpr auto ROWS = 5;

 void inputArray(int alpha[])
{
	std::cout << "Enter " << SIZE << " numbers \n";
	for (auto i = 0; i < SIZE; ++i)
	{
		std::cin >> alpha[i];
	}
	std::cout << "Alpha after reading " << SIZE << " numbers" << "\n";
	for (size_t i = 0; i < SIZE; ++i)
	{
		std::cout << alpha[i] << " ";
	}
	std::cout << "\n";
}

void doubleArray(int beta[], int alpha[])
{
	for (auto i = 0; i < SIZE; ++i)
	{
		beta[i] = alpha[i] * 2;
	}
	std::cout << "Beta after a call to doubleArray" << "\n";
	for (auto i = 0; i < SIZE; ++i)
	{
		std::cout << beta[i] << " ";
	}
	std::cout << "\n";

	//return beta[20];
}
 void copyAlphaBeta(int inStock[][SIZE], const int alpha[], const int beta[])
{
	for (auto i = 0; i < ROWS; ++i)
	{
		std::copy(alpha, alpha + SIZE, std::begin(inStock[i]));
    }
    for (auto i = ROWS; i < 2 * ROWS; ++i)
    {
        std::copy(beta, beta + SIZE, std::begin(inStock[i]));
    }

	std::cout << "inStock after call to copyAlphaBeta" << "\n";

    for (auto i = 0; i < 2 * ROWS; ++i)
	{
		for (auto j = 0; j < SIZE; ++j)
		{
			std::cout << inStock[i][j] << " ";
		}
		std::cout << "\n";
	}

}

int main()
{
    int alpha[SIZE];
    inputArray(alpha);
    int beta[SIZE];
    doubleArray(beta, alpha);
    int inStock[2*ROWS][SIZE];
    copyAlphaBeta(inStock, alpha, beta);
}
Topic archived. No new replies allowed.