frank1 has asked for the wisdom of the Perl Monks concerning the following question:
i want when i enter in like 50 and number Greater than or equal, 3 should be subtracted and then print out what is sent.
same applies to other
#!/usr/bin/perl -w use strict; use warnings; print "Enter a number\n"; my $number = <>; chomp($number); my $sendthis = ''; # this area is working if ($number) { if ($number >= 10 ) { $sendthis = $number - 2; print "You sent: $sendthis\n"; } # this area not working if ($number >= 20 ) { $sendthis = $number - 3; print "You sent: $sendthis\n"; # WHEN I ENTER IN 23 # THE OUTPUT IS # You sent: 21 ---- I DONT NEED THIS # You sent: 20 ---- THIS IS THE RIGHT ANSWER } # and this not working if ($number >= 50 ) { $sendthis = $number - 4; print "You sent: $sendthis\n"; # WHEN I ENTER IN 55 # THE OUTPUT IS # You sent: 53 ---- I DONT NEED THIS # You sent: 52 ---- I DONT NEED THIS # You sent: 51 ---- THIS IS THE RIGHT ANSWER } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: subtracting numbers
by marto (Cardinal) on Dec 23, 2020 at 10:40 UTC | |
by frank1 (Monk) on Dec 23, 2020 at 11:27 UTC | |
|
Re: subtracting numbers
by bliako (Abbot) on Dec 23, 2020 at 10:42 UTC | |
|
Re: subtracting numbers
by hippo (Archbishop) on Dec 23, 2020 at 10:43 UTC | |
|
Re: subtracting numbers
by kcott (Archbishop) on Dec 23, 2020 at 13:08 UTC |