It was fun and informative reading your detailed reply roboticus :)
It was clever to use $equal as a yes/no flag. I had solved the program like this, yesterday night(I'm entering different no.s and thinking ways where the program breaks)But now I consider your example superior. Anyway look at this:
#!/usr/bin/perl
use warnings;
print "Enter a number\n";
chomp( $a = <stdin> );
print "Enter second number\n";
chomp( $b = <stdin> );
print "Enter third number\n";
chomp( $c = <stdin> );
$big = 0;
$equal = 0;
if ( $a == $b ) {
$big = $a;
$equal = $a;
}
elsif ( $a > $b ) {
$big = $a;
}
else {
$big = $b;
}
if ( $equal == $c ) {
print "All numbers are same";
}
elsif ( $big < $c ) {
$big = $c;
print "The biggest number is $big \n";
}
else {
print "The biggest number is $big \n";
}
Having done so, it's easier to see at least one of the errors: In your reporting section, one of your if branches doesn't print anything, so if you entered 1, 2, 3 as your numbers, then $big would be less than $c, and nothing would be printed:
I completely agree. I would've spotted that error if i had formatted well.
A big thank you to PerlMonk for correcting my errors patiently. :)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.