Order of Operations Help

Ok, I wrote this simple code and it works my only question is when I dont use parentheses around the equation why do I get an incorrect average. I guess I'm trying to understand the method the computer is using to arrive at its answer

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
  #include <iostream>

using namespace std;

int main()
{
	int v1 = 0;
	int v2 = 0;
	int v3 = 0;

	cout << "Please input scores: \n" << endl;

	cin >> v1;
	cin >> v2;
	cin >> v3;

	cout << "Average = " << (v1 + v2 + v3) / (3) << endl; 

// If I use the number 1 for all 3 numbers the answer is 1 of course but without the parentheses the answer is 2. 
// It seems as though the same answer should result in both cases. 
//Please help me understand the computers math process without the parentheses

	system("pause");
	return 0;

}
Last edited on
Basic math priority: multiplication/division then addition/substraction.

v1 + v2 + v3 / 3 == v1 + v1 + (v3 / 3)
As v3 / 3 performs integer division, 1 / 3 == 0
kind of embarrassed i didnt catch onto that quicker. Thanks
Topic archived. No new replies allowed.