### Standard Deviation using Array and Class

I can't understand why the
 mean

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273`` ``````#include using namespace std; const int N = 10; class Stand_Devn { public: double miu, sum; void input(int num), mean(int num), sigma(int num); double stand_devn(int num); private: double in[N]; }; void Stand_Devn::input(int num) { double in[N] = {0}; for (int i = 0; i < num; i++) { cout <<"Enter value "<< i+1 <<": "; cin >> in[i]; } //For testing purposes cout << in[0] <<" "<< in[1] <<" "<< in[2] << endl; } void Stand_Devn::mean(int num) { double total = 0; for (int i = 0; i < num; i++) { total += in[i]; } double miu = total/num; //For testing purposes cout <<"Total: "; cout << in[0] + in[1] + in[2]; cout <<"\nMean: "<< miu; } void Stand_Devn::sigma(int num) { double sum = 0; for (int i = 0; i < num; i++) { sum += pow((in[i] - miu),2); } } double Stand_Devn::stand_devn(int num) { cout <<"\nThe standard deviation for "; for (int i = 0; i < num - 1; i++) { cout << in[i] <<", "; } for (int i = num; i , num + 1; i++) { cout << in[i]; } cout <<" is: "; return sqrt(sum/num); } void main() { Stand_Devn SD; int count; cout <<"Enter number of values (up to 10): "; cin >> count; cout << endl; SD.input(count); SD.mean(count); //SD.sigma(count); SD.stand_devn(count); }``````

 ```Enter number of values (up to 10): 3 Enter value 1: 1 Enter value 2: 2 Enter value 3: 3 1 2 3 Total: -2.77679e+062 Mean: -9.25596e+061Press any key to continue . . .```

Any help would be greatly appreciated. Thanks.
In the input function you are putting values in a local array, not Stand_Devn::in.
 ``123456789101112`` ``````void Stand_Devn::input(int num) { double in[N] = {0}; // Here, you are declaring a new variable within this scope. for (int i = 0; i < num; i++) { cout <<"Enter value "<< i+1 <<": "; cin >> in[i]; } //For testing purposes cout << in[0] <<" "<< in[1] <<" "<< in[2] << endl; }``````

Just remove that line and you should be all good to go :)
Oh, of course. Thanks very much!
Topic archived. No new replies allowed.