Dear monks,
This script was one of my very first, made late last year. Since then I have come on leaps and bounds mainly thanks to you all here. I thought that I had lost both the script and the formula for this equation but I found it just lying in a forgotten undisturbed part of hard drive. I spruced it up a small bit and hope to integrate tk's graph module into it but i seem to have a problem....

The script runs fine i.e. Perl gives no errors, but when I get to the sub confirm part thats where I have problems.

Initially it should,
if $answer is equal to "n" send you back to the start
if $answer is equal to "y" send you to the middle sub
and if $answer is equal to anything else send you back to the top of confirm.

It doesn't.

No matter what I type. I always end up going back to the start subroutine. And I'm starting to feel a bit lost. Going round in circles if you will! Any and all comments are as always very welcome. Thank you in advance.
Heres the code:
#To determine the pattern of fish reproducing #in a pond #Using the Chaos Theory &start(); ############################################################ sub start{ print "Welcome to the 'Fish in a Pond' chaos theory solution guide +.\n" . "Please enter the number of fish in the pond on the f +irst year:\n"; print "\n"; $nof = <STDIN>; print "\n"; print "Please enter the anual rate of increase: \n"; print "\n"; $roi = <STDIN>; print "\n"; print "For what period of time would you like the simulation t +o run for(in years): \n"; print "\n"; $yrs = <STDIN>; chomp($nof); chomp($roi); chomp($yrs); &confirm(); } ############################################################ sub middle{ $ans = $nof; $year = 0; print "Year $year. = $ans fish."; print "\n"; &calc(); } ############################################################ sub calc{ while($year <= $yrs) { $year = $year + 1; $i = $ans * $roi; $x = 1 - $ans; $ans = $i * $x; print "Year $year. = $ans fish. \n "; } } ############################################################ sub confirm{ print "The data that you have entered says: \n" . " * that there is $nof in the pond on the fisrt year. \n" . " * that the annual rate of increase is $roi. \n" . " * that the simulation will run for $yrs years. \n"; print " Is this information correct?(Y/N): "; $answer = <STDIN>; chomp($answer); if ($answer = "n") { &start(); } elsif($answer = "y") { &middle(); } else{ print "Please enter either Y or N. \n"; &confirm(); } } ############################################################

All the Best, Eoin...

If everything seems to be going well, you obviously don't know what the hell is going on.

Edit by tye, add READMORE


In reply to Trouble with flow control by eoin

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.