quick multiplication problem need help

how do you solve this problem?
I did it like this

int b = 4 , p =5, r =2, v=8;
double x= 10.2


B=10-v%p*2;

i did 10 - 8 % 5 * 2 and got the answer b=8

did i do this correctly? i did multiplication before modulo or do i do modulo first?
What are you trying to do?
B= 10- v % p*2;

is what im trying to solve with the above values
that are given to me
what do i do first multiply or modulo?
The C++ expression 10 - v % p * 2 is equivalent to 10 - ((v%p)*2), if that's what you're asking. See http://en.cppreference.com/w/cpp/language/operator_precedence
so modulo goes first? even though multiplication is first in the operator precedence it goes */%... on that site
Multiplication, division, and modulo (* / %) have the same precedence, and they get evaluated left-to-right, so the v % p goes first because you wrote that first.

When in doubt, use parentheses.
Last edited on
Topic archived. No new replies allowed.