in reply to Find the biggest number from three numbers

Observe this debugging output, and compare the number manuall to your if/elsif/else block
#!/usr/bin/perl -- print "Enter a number\n"; chomp( $a = <stdin> ); warn ">>> a($a)b($b)c($c)big($big)equal($equal) "; print "Enter second number\n"; chomp( $b = <stdin> ); warn ">>> a($a)b($b)c($c)big($big)equal($equal) "; print "Enter third number\n"; chomp( $c = <stdin> ); warn ">>> a($a)b($b)c($c)big($big)equal($equal) "; $big = 0; $equal = 0; if ( $a eq $b ) { $big = $a; $equal = $a; } elsif ( $a > $b ) { $big = $a; } else { $big = $b; } warn ">>> a($a)b($b)c($c)big($big)equal($equal) "; if ( $equal eq $c ) { print "All numbers are same"; } elsif ( $big < $c ) { $big = $c; } else { print "The biggest number is $big \n"; } warn ">>> a($a)b($b)c($c)big($big)equal($equal) "; __END__ Enter a number 1 >>> a(1)b()c()big()equal() at - line 4, <stdin> line 1. Enter second number 2 >>> a(1)b(2)c()big()equal() at - line 8, <stdin> line 2. Enter third number 3 >>> a(1)b(2)c(3)big()equal() at - line 12, <stdin> line 3. >>> a(1)b(2)c(3)big(2)equal(0) at - line 27, <stdin> line 3. >>> a(1)b(2)c(3)big(3)equal(0) at - line 39, <stdin> line 3.
When using 1,2,3, the program never reaches the else block which prints, because when big(2) is less than c(3)

Tutorials: Debugging and Optimization: Basic debugging checklist

Replies are listed 'Best First'.
Re^2: Find the biggest number from three numbers
by shrsv (Novice) on Dec 22, 2010 at 15:17 UTC
    Thank you very very much sir. Solved it in 5seconds. Actually it was a mistake by me. New to this programming thing. Thank you again. This made everything OK
    #!/usr/bin/perl 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"; }