I'm having a problem calculating the standard deviation of an array.
I'm using numbers 1,2,3,4,5 to check the code and the standard deviation should be 1.58, but the program is saying it is 1. Does anybody know what is wrong with the code? I was going back and forth on storing the individual deviations in a n array.
I just thought about precedence of the operators and I put parenthesis around size-1 on line 10 and the standard deviation value is correct now.
This was some other code I wrote to try to calculate the standard deviation. I'm not sure if this could have been done without using an array like I tried to do with the code below. I'm guessing it could, but it's just trickier.
What is the point of arrayDev being an array? It seems like you could just make it a double, remove its indexing in the loop, and the function would work exactly the same.
Also, it would be better to calculate the average once before the loop and use that value, rather than calculating the same average each time the loop iterates.
Edit: here's what it would look like with my changes: