Rachael,

The error message shows that you have not made use of the scalars that you initialized at the top of the module. In the condition based on the return answer to the question, "Which operation would you like to undertake?" you have set the condition to compare the literal word "Add" rather than comparing it against the scalar $add which holds the string literal 'Add'. You could try either "$add" - or $add, as the scalar is interpolated (expanded to the value) within double quotes so they are equivalent.

Also you may need to set up a condition so that it tests the operation input for either a '1' or the word 'Add' and then carries out the relevant operation.

chomp($ask); # chomp() here rather than chop() if ($ask eq $add) { $z = $x + $y; print "$x + $y = $z";}

or to start anticipating differing answer strings:

chomp($ask); if ($ask eq $add || $ask == 1) { $z = $x + $y; print "$x + $y = $z";}

you may like to think of prompting the participant again if they supply an invalid operation request, for example, if they spelt subtraqt incorrectly.


In reply to Re: my program will not display a correct answer, to a random question? by Don Coyote
in thread my program will not display a correct answer, to a random question? by rse2

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.