QUOTE(stezz @ 9 Dec, 2006 - 02:53 PM)

Hi guys,
I have a question about passing arrays to functions. The program is simple, it asks the user for numbers which it stores in an array (maximum of 20). I've written a function that processes the array to calculate the minimum, maximum and average of the numbers stored in it.
As there are three different values I need the function to return, can I do it in one function, or do I need three seperate functions. Two of the three values are intergers and the third is a float.
Hope somebody can help.
Regards,
Stezz
Indeed, it would probably be best to make separate functions for each (average, maximum, minimum), but...there is another way that doesn't involve structures. You could pass pointers to the integers and float representing the minimum and maximum and average. Then the function could modify those values through the reference parameters.
CODE
int arr [20];
int maximum;
int* maxPtr = &maximum;
int minimum;
int* minPtr = &minimum;
float average;
float* avPtr = &average;
/*fill the array*/
/*now you'd call the function that had
a prototype like so:
void doAll(int[] array, int*min, int*max, float*av)
*/
doAll(arr, minPtr,maxPtr,avPtr);
/*print out the three values which have been set by doAll*/
Then in the doAll function, you would just refer to the pointers as so:
CODE
void doAll(int[] array, int*min, int*max, float*av)
{
/*sort array*/
*min = array[0];
*max = array[19];
*float = /*the average you calculated*/
}