in reply to my program will not display a correct answer, to a random question?
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.
|
|---|