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:
 ``12345678910111213141516171819202122232425262728293031323334353637`` ``````#include #include 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? " << 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.