Adding elements of an array in a function

I started trying to learn C++ a few weeks ago. I'm working on a program that is supposed to add the elements of the two arrays and store it in the third array. When I went to test the plusArrays function I get 0 for all of array3 (which is what it should originally be initialized to, right?)

Why isn't my function summing the arrays?
Am I just not properly calling the plusArrays function?

I feel like the problem is really simple, but I'm missing it.

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
#include <iostream>
#include <array>
using namespace std;

const size_t arraySize = 20; //Standardizes array size. Const variable makes it unchangeable.


array <int , arraySize> array1 = {7, 21, 3, 99, 14, 65, 23, 44, 8, 19, 54,
	33, 27, 89, 64, 31, 78, 92, 12, 11}; //First array
array <int , arraySize> array2 = {8, 92, 58, 61, 38, 27, 29, 41, 36, 15, 35,
	67, 4, 7, 12, 71, 41, 37, 78, 21}; //Second array
array <int , arraySize> array3 = {}; //Third array, initialized to all zeroes?

void plusArrays()
{
	for (size_t i = 0; i < arraySize; ++i)
		array3[i] = array1[i] + array2[i]; 
}

int main()
{
	void plusArrays();
	cout << array3[1] <<endl;
	return 0;
}
Last edited on
You aren't calling the function.

1
2
3
4
5
int main()
{
    plusArrays();
    cout << array3[1] << endl;
}
Oh dear I feel so dumb. Thanks for the help.
Topic archived. No new replies allowed.