Avarage calculator

Hey!
I was doing some stuff and i made this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<iostream>
using namespace std;
int main() {
	int a,b,c;

		cout<<"Write two numbers that you want to get avarage"<<endl;
	cin>>a;
	cin>>b;
	

	c=a + b/2;

		cout<<"Your number is: "<<c<<endl;

	char z;
	cin>> z;

	return 0;
}



I get random number... i think c=a + b/2; doesn't work good.


Ty for help!
search about operator precedence and integer division
what what what? i am new to whole c++ thing ^^
Those are about mathematics
Or just add brackets around a+b... Mathematics rules state that you divide before adding.. Brackets however are to be solved before going on with the rest..

In other words, by adding brackets around the a+b, it'll first add those, and then divide it by 2 :)
kaduuk right u need to add an Brackets at a+b. because in the MDAS rule. . .
ty guys
Topic archived. No new replies allowed.