Mod operator

Im confuse as to how to use mod operator,
can someone please anxplain how and why to use
this??

Thanks
I'm assuming you mean modulus (%).

Modulus returns a remainder. For example, if

int x=5
int y=2

then dividing

x/y

will return

2

because integers cannot handle decimals. modulus, however

x%y

will return

1

because 5/2= 2 remainder 1
and what about if is the other way around??

int x=34
int y=5

x/y

Sometimes the quotient is the answer and sometimes in the remainder is the answer

or

what about 34%5
34/5 would return 6, because integers can't handle decimals or remainders.

34%5 would return 4, because 34/5 is 6 remainder 4. So if you made int z=x%y (using your above values) then cout << z would display 4
I’m writing a program were I have to use MONTH,DAY and YEAR
And the month and day have to match the year.
For example 6*10=60
And I’m not sure how to input mod operator into this problem.
Will this be :

Int month = 0;
Int day = 0;
Int year = 0
X= ?
Y= ?
This is where I’m confuse
Why are you using modulus at all? It looks (unless I'm misreading this) like it's a simple multiplication problem
Topic archived. No new replies allowed.