Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: modulus question

by vinoth.ree (Monsignor)
on Feb 03, 2015 at 05:50 UTC ( [id://1115341]=note: print w/replies, xml ) Need Help??


in reply to modulus question

To check if a number $day is divisible by divisor(3), use the modulus operator, %:

If the number divisible by 3 then the modulus will return remainder 0, so the if condition will fail so add your logic in else condition.

if ($day % 3) { # does not divide cleanly } else { # does. }
(OR)

Even you can use the same as your if(($day%3) == 0) condition of checking the reminder is equal to 0. In this case you can add your logic in if(..) itself


All is well

Replies are listed 'Best First'.
Re^2: modulus question
by GrandFather (Saint) on Feb 03, 2015 at 06:47 UTC

    vinoth in a case like this by not providing any code there is a chance that the OP will show us what he has tried and thus allow us to provide much better help than we can by just giving a dollop of code.

    Very often the errors beginners make fall into common patterns and tell you a lot about how they are thinking and where the root of their problem really lie. By just giving a solution, even if we take time to explain how the solution works, beginners will run off happy, but none the wiser.

    Perl is the programming world's equivalent of English
      Hi GrandFather,

      Yes I agree with you, I regret for that. As per my understanding I though he just confused if(....) condition with modulus(%) operator. That's why I just given him the explanation.


      All is well

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1115341]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-19 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found