I am writing an average function that takes the average of an array, and returns the answer to 2 decimal places. The only way I found online to do this, however, is by using printf()
or cout()
.
But I do not want it to be printing out each time this function is called because it is used in other functions such as a variance equation and standard deviation equation that shouldn't be displaying the average function.
If anyone could tell me a way to do this, I would be eternally grateful. I think my question is broad enough that code isn't really needed, but here it is anyway just in case. It just continues for quite a few decimal points. Not sure if that's the exact value or a cut off point.
double avg(int a[],int n) // compute the average of n data storing in the array a
{
double addsum = (double)sum(a,n)/(double)n;
return addsum;
}