Helllo!

I have quite a big problem!
I have to make an array in one function (NOT MAIN!!!) that does not return the array, but just the average value of its elements to main.

Then, I have to use elements from the same array to calculate other values form them (can also be in main).

Is that possible at all?

How can I reach array from function f (not main) if the function f is not returning array?

Many thanks!!!
closed account (Dy7SLyTq)
just pass the array to your function ie:

 ``12345678910111213141516171819202122232425`` ``````#include double CalculateAverage(int DataSet[], int ArraySize) { int Average = 0; for(int Counter = 0; Counter++ < ArraySize;) Average += DataSet[Counter]; return Average / ArraySize; } int main(int argc, char *argv[]) { int DataSet[10] = {0}; int Counter = 0; while(Counter++ < 10) { printf("Enter Number %d: ", Counter); scanf("%d", DataSet[Counter]); } printf("Average: %f\n", CalculateAverage(DataSet, 10)); }``````
put that into a function

 ``12345678910`` ``````int main() { int sum = 0; int average = 0; int array[10] = {1,2,3,4,5,6,7,8,9,10}; for (int i = 0; i < 10; ++i) sum+=array[i]; average = sum/10; cout<<"Average:"<
closed account (Dy7SLyTq)
he made it quite clear that it cant be in main and i did put it in a function
oh haha thats my bad im kinda drunk i meant to take out the int main and just put the body into a function but i was actually talking to enemy
Last edited on
Hello!
What is happening with DataSet[10] in main?

I ment, I have array declared and INITIALISED in function, then I want to translate the whole (full!) aray into main, with all the elemnts values, like in function...

or at least, to call elemets from array in function in main...

I can do the opposite (call elements from main-array in the function.

Any help?

Please, am the ABSOLUTE beginner, I appologise

many thanks!
declare the array global(i know that it is a really bad idea but situation demands it....).
Y, u are right, not best idea but practical if it goes.

Maybe some examples, as simple as possible?

Many thanks!

Topic archived. No new replies allowed.