for (int i = 0; i <= size; i++)
{
total += array[i];
}
Given size is the size of the array, you are trying to access the final element of the array which doesn't exist.
(arrays start at 0 and end at 1 below how many elements)
In the moments() function you are using local variables (ave and stdDev) .
These are only available in the moments function and do not affect/change the variables of the same name in the mainfunction.
You should pass these variables by reference or by pointer