Returning functions

I have two functions I need to write and I am having trouble writing them.

First function receives an array of long and returns the 2nd value stored in the array.

Then second function receives a 2 dimensional array of long double with 10 columns. Also you will receive a short value representing the number of rows. The function totals all of the amounts in the array. The total of the values is returned as a long double.

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

Here is the 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
36
37
38
39
40
41
42
43
44
45
46
  #include <iostream>

   using namespace std;

   int *F1(long array[], int size);
   long double F1(long double array[][10], short rows);

int main()
{

long ARRAY3[4] = {1, 2, 3, 4};
	int *secondValue = F1(ARRAY);

	cout << "The second value of ARRAY3 is " << secondValue << endl;


long ARRAY4[2][3] = {{ 1, 2, 3,}, {2, 3, 4}};
	long double total;

	total = F1(ARRAY4, 2);

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

	system("pause");
	return 0;
}
int *F1(long array[])
{
	int *ptr;
	ptr = array[1];
}


long double F1(long double array[][10], short rows)
	{
		long double total = 0;
		for(int i = 0; i < rows; i++)
		{
			for(int j = 0; j < 10; j++)
			{
				total += array[i][j];
			}
		}
		return total;

	}
What are you stuck on?
I figured it out!

The function for long array should of been like this:

int F1(long array[])
{
return (int)array[1]; //convert the long to int to return
}

and the long double F1 ARRAY4 was coded wrong it should have been something like this:

long double ARRAY4[2][10] = {{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};

The columns where not set right.

Thanks for looking at the code.

R.
Topic archived. No new replies allowed.