rshoe has asked for the wisdom of the Perl Monks concerning the following question:

My program should display multiples of a chosen integer between 200 and 100, For example, if a user enters 5, the results would be 200 195 190 etc... The program must use a while loop If anyone can help me I would appreciate it. Thanks. Here is my code
#!c:\Dwimperl\perl\bin\perl.exe use strict; use warnings; #### prompt a user to enter an integer print "Enter an integer "; my $integer = <STDIN>; chomp $integer; my $i = 199; ### use either a while loop or an until loop to count down from 199 to + 99 while($i >= 99){ ### display all multiples of the integer print $i - $integer . "\n"; --$i; }

Replies are listed 'Best First'.
Re: count down with while loop
by McA (Priest) on Oct 23, 2014 at 16:07 UTC
    print "$i\n" if $i % $integer == 0;

    McA

      McA: Thank your for your reply. I see what I missed. You were right on the mark. I appreciate all your help. Thanks again. Randy
Re: count down with while loop
by johngg (Canon) on Oct 23, 2014 at 16:17 UTC

    Probably quicker to jump in increments of $integer.

    $ perl -Mstrict -Mwarnings -E ' my $lower = 100; my $upper = 200; my $int = 15; my $start = int( $upper / $int ) * $int; while ( $start >= $lower ) { say $start; $start -= $int; }' 195 180 165 150 135 120 105 $

    I hope this is helpful.

    Cheers,

    JohnGG

      JohnGG: Thanks for you help. The user puts in the amount to count down and then it is adjusted from there. I appreciate all your help. Thanks, R.
Re: count down with while loop
by GotToBTru (Prior) on Oct 23, 2014 at 16:08 UTC

    You've got the count-down while loop, except you aren't using your supplied value of $integer for anything. What was your plan for determining if any of those values were multiples of 15?

    1 Peter 4:10
      GotToBTru: Thank your for your reply. The fifteen was just an example. The user puts in the amount they want to use then it is adjusted from there. The code I got earlier seem to work. Thanks again for all your help. R.
Re: count down with while loop
by ww (Archbishop) on Oct 23, 2014 at 16:39 UTC

    Parent (OP) has a strong stink of homework... but was not labled. Downvoted.


    check Ln42!