Good day! I have been trying to code a program with 2 functions: One which takes a vector of integers and calculates the average. The other is to calculate the standard deviation. The user is asked to enter an integer which is inputed as the size of the vector. The vector will then be filled with random integers. My problem is that the program works fine, except that it keeps returning the deviation as 0.
The formula for standard deviation is here: http://www.social-science.co.uk/research/?n1=&id=93
Thanks for your help!
Hello, your problem seems to be that you were unknowingly throwing away the precision that you needed. 1 / vector::size will always evaluate to 0, unless vector::size is 1, then it will evaluate to 1. To fix that, we cast vector::size to a double.