Standard Deviation using Array and Class

I can't understand why the
mean
function isn't adding properly:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
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.
1
2
3
4
5
6
7
8
9
10
11
12
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.