calculating standard deviation from file

Here's my attempt:

input.open(name);

if (input.fail()){
cout <<"Error opening file"<<endl;
}

while (input>>numbers)
{
counter++;
total += numbers;

average = total/counter;
st_dev= sqrt((pow((numbers-average), 2))/(counter));
}
cout << "The Standard Deviation of all the numbers is: "<<st_dev<<endl;
input.close();

Copy of the output:

Error opening file
The Standard Deviation of all the numbers is: -9.25596e+061
Press any key to continue . . .


Its not giving me the right answer. THanks in advance.
Last edited on
Topic archived. No new replies allowed.