can someone explain how the vlaue is 6?

as the tittle suggests, can someone explain to me how the value here is 6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int Operation1(int a, int b)
 {return (a / b);
}

int Operation2(int b, int c)
 {return(b -c);
}

int main()
 {int a = 9, b = 3, c = 5;
//don’t forget to work out the nested functions first

int RESULT = Operation2(Operation2(a,b), Operation1(b,a));
std::cout << RESULT;
}
Last edited on
int RESULT = Operation2(Operation2(a,b), Operation1(b,a))
= subtract( subtract(a,b), integerDivide(b,a) )
= subtract( (9-3), (3//9) )
= subtract( 6, 0 )            - note the integer divide
= 6 - 0
= 6
i see, i kept calculating as 0.3, and not 0. Realkised now its an int. Thanks!
Last edited on
can someone explain to me how

Can you explain to us how you did work out the problem and what result you did get?
Topic archived. No new replies allowed.