a function that recieves 5 arguments and returns 5

The title might not be of much clarity but what I am tyring to do is write a program that will consist of a main program holding an array of 5 elements. The main function will pass these values as arguments to another function and get a return value for each argument passed.
say if the function recieves an argument 5, its gotta add 1 to 5, similarly for 6 its gotta add 1 to 6. and then return all these values to main, so they can be printed out. my code is really imconplete, but just general outline would surely help.

//write a function that would be called 5 times for 5 different values. each value specifies the arithmatic sum from zero to that value

#include <iostream>
using namespace std;
int sum_array(int);
int sum;
int main()
{
const int size = 5;
int array1[size] = {5,6,7,8,9};


//passing the array as arguments to a function. one at a time
for (int index = 0; index < size; index++)
//calling the function five times, is it?
sum_array(array1[index]);
cout << sum << " " << endl;
return 0;
}
int sum_array(int number)
{
for (int count = number; count > 0; count--)
{
sum += count;
array2[i] = number[count];
}
return sum;
}
C++ can only "return" one object, however this can be any type of object, so you could return an array/vector of items.

Also, if your function is just returning modified values of the input, you could consider passing the input as references, so that the values change in the main function as well.
closed account (EzwRko23)
Functions should not modify their arguments, unless REALLY needed.
You don't need to modify arguments for this, or do anything out of the ordinary.

Your function should not be changing any array, it should just be returning the sum. Whatever code is calling this function should be the one putting the return value in an array (if it even needs to go in an array at all).
Topic archived. No new replies allowed.