# Objective-C help please (newby explanation needed :))

by newbim
7 replies
• |
Hi. I'm reading a "For Dummies" book on Obj-C and it's talking about modulus. It quotes an example more than once:

"2 divided by 3 equals 2" ????

It does it again. Im not a math genius, and I know in context (where the type is an int and therefore a whole number) but 2 / 3 = 0.666667, not 2.

Can someone explain the simple math to me, I've a feeling I'm going to feel very stupid when I see the explanation, lol.

Cheers,

Newbim.
• Not sure what they are saying without context but the modulus operator will find the remainder.

It's often used to set up a condition for something like creating 2 columns.

You loop through a result set using a variable, say "i".

If modulus i is divisible by 2, data goes into one column, else it goes into another.
{{ DiscussionBoard.errors[4249596].message }}
• Thanks for that.

It was talking about modulus and mathmatical functions.

This is how they use it:

a = 2
b = 3

c = a % b;
NSLog (@"a %% b = %i", c);

Results in:

a % b = 2

-- I can understand how b % a = 1, because the remainder modulus is 1, but I don't get it the other way round because 3 doesn't go into two at all.

I know it's probably a really simple thing but Ive been trying to figure it for three days now, need a fresh pair of eyes on it. Haha.

Thanks.
Signature
If what I said helps, let me know, throw me a 'thanks'.
{{ DiscussionBoard.errors[4258672].message }}
• Mod as a formula actually works out to:
a - (b * (a \ b))

but i still don't know why. But it works.
{{ DiscussionBoard.errors[4263570].message }}
• 3 goes into 2, 0 times, with 2 left over.
{{ DiscussionBoard.errors[4270570].message }}
• Hey Newbim,

This isn't an answer to your specific question but it might help for your overall knowledge of obj c.

There are some awesome videos on youtube by the user 'TheNewBoston'. Just search for that user. Freakin awesome tutorials.

Let me know if it helped
MB
{{ DiscussionBoard.errors[4270934].message }}
• the result of the mod operator is the "left over". whatever you have left over is the answer. 3 goes into 2 zero times, with 2 "left over".

when i first learned about this operator, i always told myself "left over" (as was mentioned earlier).
{{ DiscussionBoard.errors[4271722].message }}
• Hi everyone.

Thanks for all the assistance - it has really helped.

I think I get it now. So the two 'left over' is the original 2 that we were trying to divide into 3... if that makes sense?? haha.

I know may have seemed like a silly question, but I REFUSE TO LET THE COMPUTERS BEAT ME, haha.

Thanks again, as always, the warrior community has come through!!

Cheers,

Andy. .
Signature
If what I said helps, let me know, throw me a 'thanks'.
{{ DiscussionBoard.errors[4274622].message }}

• ### FCC coming after "Lead Generator Loophole"

RRM20

The FCC is criticizing the practice of lead generators obtaining prior express written consent from a consumer en masse by listing a large number of partner companies from which the ... [read more]

• ### Have you seen any summer movies at the theater??

discrat

Just got back from Pixar's Inside Out 2. It's a cute animated movie. Even though it was good, I liked the first one a little better. Any movies you have ... [read more]

• ### This Ever Happen to You?

Mark Singletary

My dog started acting crazy and since she got louder and louder, I went outside to take a look. I thought it was one of the neighborhood male cats ... [read more]

• ### Seeking Advice on Effective Marketing Strategies for Insurance Funds

gerard23

Hello Warriors, I'm currently exploring different marketing strategies for insurance funds and would love to hear your insights and experiences. What strategies have you found most effective in promoting insurance ... [read more]

• ### How much effort is being put into stifling noobs?

Shancock

So like the title says... are people out there trying to stifle competition at the grassroots with misinformation? Am I being paranoid? I am a bit of a contrarian I ... [read more]