in reply to Homework Problems

I'm a beginner to perl also. This was a good problem for me to try. Here's my code. I left my debugging print statements in there. From what I observed, the G = 2 and the I = G blocks will never execute. G is set to 0 in the H = 2 block and never change to anything else. I and G never equal the same thing until the last else statement and the program doesn't loop back around that I = G statement again.
use strict; use warnings; my $G = 18; my $H = 2; my $I = 13; print "Initial values\n"; print "g=$G\th=$H\ti=$I\n"; if($H == 2) { &ChangeGI($G, $I); } print "Values After H ==2\n"; print "g=$G\th=$H\ti=$I\n"; while ($I > 7) { &ChangeHI($H, $I); print "In while loop I > 7\n"; print "h=$H and i= $I"; } print "After while loop\n"; print "g=$G\th=$H\ti=$I\n"; if($G == 2) { &ChangeG($G, $H); } print "After G ==2\n"; print "g=$G\th=$H\ti=$I\n"; if($I == $G) { &ChangeG($G, $H); } else { &ChangeHI($H, $I); } print "After IF I== G\n"; print "g=$G\th=$H\ti=$I\n"; print "The final results are G\: $G and H\: $H and I\: $I\n"; ####################### sub ChangeGI { while($I > 5) { $I = $I - 3; $G = 0; } } sub ChangeHI { $H = $H + 2; $I = $I - 4; } sub ChangeG { my ($G, $H) = @_; $G = $G + 1; $H = $H -1; } #Initial values #g=18 h=2 i=13 #Values After H ==2 #g=0 h=2 i=4 #After while loop #g=0 h=2 i=4 #After G ==2 #g=0 h=2 i=4 #After IF I== G #g=0 h=4 i=0 #The final results are G: 0 and H: 4 and I: 0