There is a lot of wrong stuff with howfaraway function.
first, newarray,oldarray, and avg are integers variables. Not arrays, as you think when you did newarray[i] = oldarray[i].
Besides, i is an array not an index.
Also, avg is not initialized. Hence, you'll have junk in the result of the manipulation at line 55.
void howfaraway()
{
// ... declare and set newarray
return newarray;
}
The function claims to return no value (void on line 1), yet the code attempts to return something.
If the newarray were an array, then it could not be returned; an array is not a valid return type.
(The std::array<double> is an object type though and thus a valid return type.)
However, an array parameter is effectively a by reference parameter.
This does change an array of the caller:
1 2 3 4 5 6
void howfaraway( double newarr[], constdouble oldarr[], size_t n ) {
// newarr must be >= oldarr
for ( size_t i=0; i < n; ++i ) {
newarr[i] = oldarr[i];
}
}