By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

help with the if statement

P: n/a
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?

Mar 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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";
}

Mar 18 '07 #2

P: n/a
ya*********@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?
Did you mean 3 is a factor of ABC ? If so then:-

if ( ABC % 3 == 0 )
{

}

Otherwise, if "3 is a multiple of ABC" means that ABC has to be either 1
or 3 since 3 is prime.
Mar 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.