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

In reply to Re: Homework Problems by mikasue
in thread Homework Problems by kbjones81

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.