Need some help !

Sep 7, 2015 at 10:02pm
How do you code a question that ask if the first integer is a multiple of the second integer?
1
2
3
4
 if (a%b==2) {
cout<<a<<"is a multiple of b";
return 0;
}


i realize that its any number can be a multiple of another number as long as it doesn't have a remainder... so im a bit lost there. 2 is not necessarily way to do it.
PLease halp. :)
Sep 7, 2015 at 10:11pm
You have answered your own question. What operator is used to find the remainder?
Sep 7, 2015 at 10:54pm
well, they didnt tell you what operator to use. Also, what if its the first integer is 10 and the second integer is 100. So its going to be 10X10. it can be divided into 100 w/o any remainder left. In the code, i only have 2 but if that wasn't the case and its 10...how does that work. Or im confusing myself?
Sep 7, 2015 at 11:11pm
You are confusing yourself. As you said if a number is a multiple of another it will have a 0 remainder, that isn't hard to change in your code.

http://www.cprogramming.com/tutorial/modulus.html
http://stackoverflow.com/questions/12556946/how-does-the-modulus-operator-work
Topic archived. No new replies allowed.