How to return a total for two arrays

I am working on a function that takes two arrays and adds them up for a grand total.

Here is what I am trying to do:

write a function in full, including header line and body called F1. It receives 4 arguments, two arrays of short and two int's, one for each array, containing the count of array elements in that array. The function computes one grand total for both arrays. It then returns the grand total.

If anyone can help me I would appreciate it
Thanks,
R.

Here is my code I have so far:

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
  #include <iostream>

using namespace std;

int F1(short array1[], short array2[], int count1, int count2);

int main()
{

	short ARRAY1[3] = { 1, 2, 3};
	short ARRAY2[3] = {1, 2, 3};

	int total;

	total = F1(ARRAY1, ARRAY2, 3,  3);

	cout << "The total is " << total << endl;
	
	
	system("pause");
	return 0;

}

int F1(short array1[], short array2[], int count1, int count2)
	{
		int total = 0;

		for(int count = 0; count < count1; count++)
		{
			for(int count = 0; count < count2; count++)
				total += array1[count] + array2[count];
			}		
		return total;
	}
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
#include <iostream>

using namespace std;

int F1(short array1[], short array2[], int count1, int count2);

int main()
{

	short ARRAY1[3] = { 1, 2, 3};
	short ARRAY2[3] = {1, 2, 3};

	int total;

	total = F1(ARRAY1, ARRAY2, 3,  3);

	cout << "The total is " << total << endl;


	system("pause");
	return 0;

}

int F1(short array1[], short array2[], int count1, int count2)
	{
		int total = 0,x=0,y=0;

		for(int count = 0; count < count1; count++)
            x+=array1[count];
		//{
        for(int count = 0; count < count2; count++)
            y+=array2[count];
				//total += array1[count] + array2[count];
			//}
		return total=x+y;
	}
Thanks Chriscpp for the quick reply.

The code you sent worked great.


Thank you for all your help!
R.
Topic archived. No new replies allowed.