Standard Deviation of 4 numbers.

Note - This is homework. Make a program that computes/outputs the mean and standard deviation of a set of four integers that are input by the user.

The problem I'm specifically asking about is how to calculate standard deviation in C++. The examples that I find of S.D. are either not very clear, or way beyond my level. (I know lots of errors, but I need the equation first.)

My code thus far: (in progress, not finished)
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
//***********
//Mean/Standard Deviation Program
//Computes and outputs mean and standard deviation of a set of four integer values input by a user.
//***********

#include <iostream>
using namespace std;

int main ()
{

//Defining input numbers, mean and standard deviation.

float numberOne <<
float numberTwo <<
float numberThree <<
float numberFour <<
float mean <<
float standardDeviation <<

//User inputs numbers.

cout << "Input your first number." << numberOne
cout << "Input your second number." << numberTwo
cout << "Input your third number." << numberThree
cout << "Input your fourth number." << numberFour

//Calculates mean.

mean = (numberOne + numberTwo + numberThree + numberFour) / 4

//Caculates standard deviation.


//Output of mean and standard deviation.

	cin >> "The mean is " >> mean >> "and the standard deviation is " >> standardDeviation >> "." >> endl;
	
return 0;
}
Last edited on
First of all, don't you see anything strange with the syntax highlight as you posted your code?

Second of all try (re)reading the tutorial on this site :
http://www.cplusplus.com/doc/tutorial/
especially the
Basics of C++
section.
I know there are several things wrong, as I said, but I'm not sure how to tweak several parts of it without the code.

(I'm not that good yet. I need to see everything to even start to fix it.)

Edit - The red is gone, there was one symbol wrong. I tweaked the output to combine it into one sentence.
Last edited on
Every statement in c++ is separated by a ; (semicolon).

Declaring a variables :
float numberOne;

Asking for input (extracting characters in a formatted way from the input stream) :
cin >> varibale;.

Writing a variable to the output stream :
cout << varibale;.

About SD:
http://en.wikipedia.org/wiki/Standard_deviation
Alright, you you VERY much ROmai. I'll start working it out, and I'll come back with the next problem, lol.
Topic archived. No new replies allowed.