writing code to find standard deviation and the median?

I am also supposed to find and print out the median and standard deviation, but how would i do that? The user can enter any order and any kind of numbers, so how can i separate them to find a median with code? I also dont know how i would code the standard deviation either... Any help would be greatly appreciated!

Here is my code:

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
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;

int main()
{
    float numbers[15];
    float sum, lowest, highest;
    float min, max, range, stDev, mean, median;
    float above = 0, below = 0;


    sum = 0;
    for(int testNum = 0; testNum < 15; testNum++)
    {
        cout << "Please enter your 15 numbers: ";
        cin >> numbers[testNum];
        sum = sum + numbers[testNum];
    }
    mean = sum/15;
    for(int testNum = 0; testNum < 15; testNum++)
    {
        if(numbers[testNum] < mean)
        {
            below++;
        }
        else if(numbers[testNum] > mean)
        {
            above++;
        }
    }
    lowest = numbers[0];

    for(int testNum = 0; testNum < 15; testNum++)
    {
        if(numbers[testNum] < lowest)
            lowest = numbers[testNum];
    }

    highest = numbers[0];
    for(int testNum = 0; testNum < 15; testNum++)
    {
        if(numbers[testNum] > highest)
            highest = numbers[testNum];
    }

    cout << "Your mean is: " << sum/15 << endl;
    cout << "Your range is: " << highest-lowest << endl;
    cout << "Your median is: " << median << endl;
    cout << "Your standard deviation is: " << stDev << endl;
    cout << "Your maximum is: " << highest << endl;
    cout << "Your minimum is: " << lowest << endl;


    return 0;
}
Topic archived. No new replies allowed.