in reply to how to make perl only print whole numbers

You can divide every number by 2 (or by any number other than zero), you just won't always get an integer result.

That's why your code prints also fractional numbers - it never checks for integer divisibility.

One good way to do that is to use the % infix operator (modulus operation), which gives you the reminder of a division. So for example 7 % 3 is 1, because if you divide 7 by 3, the remainder is one. If the remainder is zero, the second number evenly divides the first.

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: how to make perl only print whole numbers
by derpp (Acolyte) on Aug 03, 2010 at 22:30 UTC
    thanks :) that really helped.
Re^2: how to make perl only print whole numbers
by rowdog (Curate) on Aug 04, 2010 at 10:38 UTC

    Update: nevermind, sigh.

    Just to be boldly pedantic...

    You can divide every number by 2 (or by any number other than zero or one), you just won't always get an integer result.

      Every number includes 1.5, and 1.5 / 1 does not give an integer result.

      The OP code even allows you to enter such numbers, since the input has no validation at all.