Problem with calculating the mean.

cout << "\n\nThe Mean of your Numbers are: " << userNumbers[0] + userNumbers[1] + userNumbers[2] + userNumbers[3] + userNumbers[4] / 5;
I'm trying to calculate the mean of 5 numbers, but what the program does is a+b+c+d+e/f. Which is wrong, and it should go a+b+c+d+e=f and then f/g - like we all learned in school.
I've tried different ways but I always ending up getting numbers like "19247987264" ridiculously long numbers.
Here's the rest of the program:
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
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int userNumbers[5];
    string userResponce;

    do{
    cout << "\t Welcome, I will try to calculate the Mean, Median and Range" << endl;
    cout <<  "\t            of your chosen numbers." << endl;

    cout << "\nPlease 5 Enter Your Numbers here: " << endl;
        for(int i = 0; i < 5; ++i)
        {
            cin >> userNumbers[i];
        }

        for(int i = 0; i < 5; ++i)
        {
        cout << "Your Chosen Numbers: " << userNumbers[i] << endl;
        }

        userNumbers[0] - userNumbers[4];

        cout << "\nThe Range of your Numbers are: " <<  userNumbers[4] - userNumbers[0];
        cout << "\n\nThe Median of your Numbers are: " << userNumbers[2];
        cout << "\n\nThe Mean of your Numbers are: " << userNumbers[0] + userNumbers[1] + userNumbers[2] + userNumbers[3] + userNumbers[4] / 5;

        cout << "\n\nDo you want to use this again? <Yes/No>" << endl;
        cin >> userResponce;
    }while(userResponce == "yes");
}


 
cout << "\n\nThe Mean of your Numbers are: " << (userNumbers[0] + userNumbers[1] + userNumbers[2] + userNumbers[3] + userNumbers[4]) / 5;


When it doubt, use parentheses.
Haha, thank you! I should have remembered BIDMAS
Topic archived. No new replies allowed.