On Mar 18, 11:10 am, yansong1...@yahoo.com wrote:
So say i got a variable ABC, how do i do a if statement to check if
the number 3 is a multiple of ABC?
I'm thinking if (ABC/3 == ####)...suggestions?
Me thinks that this is a place to use the modulus operator.
The modulus operator finds the remainder of division of one number by
another. Its symbolized by the % sign.
So,
If ABC was 30, then ABC % 3 is equal to zero.
Any multiple of 3 in ABC, when % with 3 should equal zero.
Hence:
if((ABC % 3) == 0)
{
cout << "multiple of 3";
}
else
{
cout << "not a multiple of 3";
}