Standard Deviation

How exactly do you use this formula?

sdx = sqrt((sumx2 - (sumx * sumx)/n)/(n-1)

I was told to use that formula in my program but I don't understand how it works could anyone explain it to me please.
I figured out I need header to use the function sqrt.
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
74
#include <iostream>
using namespace std;

void Display_Menu();

int main ()
{
    Display_Menu();

	int choice,grad,count,sum;
	int min = 100;
	int max = 0;

	cin >> choice;

    while (choice != 'q')
	{
    if (choice == 1)
		{
			while (grad >= 0)
			{
		     cout <<"Enter the necessary grades.\n";
			 cin >>grad;
			 if (grad >=0)
			 {
				 sum = sum + grad;
				 count++;
			 }
		    if (grad <min && grad > 0)
		    {
			  min = grad;
		    }
			if (grad > max)
		    {
			  max = grad;
			}
			}
		  cout << min;
		  cout <<"Enter you're next choice.\n";
		  cin >> choice;
	    }
	if (choice == 2)
	{
	  int average;
	  average = sum/count;
	  cout << "This is the average of the grades entered.\n" << average << "\n";
	  cout << "Select you're next choice.\n";
	  cin >> choice;
	}
	if (choice == 3)
	{
	}
	if (choice == 4)
	{
		cout << "This is the highest grade you entered.\n" << max << "\n";
		cout << "This is the lowest grade you entered.\n"  << min << "\n";
	}
	cout << "Goodbye see you next time.\n";
	break;
	}
	system ("pause");
	return 0;
}

	
void Display_Menu()
{
	cout << " Option 1 : Enter grades ( Quit with a negative value)\n";
	cout << " Option 2 : Display the Mean(average) for the grades\n";
	cout << " Option 3 : Display the standard deviation for the grades\n";
	cout << " Option 4 : Display the high and low grades\n";
	cout << " Option 5 : Enter 'q' to quit\n";
	cout << "Enter you're choice (1-5)\n";
}



I need to add the above standard deviation formula in my choice ==3 but I am not sure how the formula works. Sorry if the program looks messy I am trying to figure out how to do it first before actually cleaning it up.
Topic archived. No new replies allowed.