rse2 has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to make my program 1. ask a user to type in a number 2. ask user to type in another number. 3.asks user what is to be done add, subtract, divide, multiply. 4. display correct answer on screen.
So far i got this done.
#! /usr/bin/perl -w $add = "Add"; $subtract = "Subtract"; $multiply = "Multiply"; $divide = "Divide"; print "Type in a number: "; $x = <>; chop($x); print "Type in another number: "; $y = <>; chop($y); print "What would you like done?\n\nYour choice is:\n1) Add\n2) Subtra +ct\n3) Multiply\n4) Divide\n"; $ask = <>; $z = $x + $y; if ($ask eq "Add") {print "$x + $y = $z";}
For know i'm trying to figure out the adding part.
When i perl it i get
Name "main::multiply" used only once: possible typo at rachael.pl line + 12. Name "main::add" used only once: possible typo at rachael.pl line 10. Name "main::divide" used only once: possible typo at rachael.pl line 1 +3. Name "main::subtract" used only once: possible typo at rachael.pl line + 11. Type in a number: 4 Type in another number: 5 What would you like done? you choice is: 1) Add 2) Subtract 3) Multiply 4) Divide 1 root:rachael {103}
can somebody please tell me what i could do to make it diplay the correct answer? Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: my program will not display a correct answer, to a random question?
by toolic (Bishop) on Aug 04, 2011 at 16:50 UTC | |
|
Re: my program will not display a correct answer, to a random question?
by Anonymous Monk on Aug 04, 2011 at 16:47 UTC | |
|
Re: my program will not display a correct answer, to a random question?
by Don Coyote (Hermit) on Aug 05, 2011 at 06:51 UTC | |
|
Re: my program will not display a correct answer, to a random question?
by ig (Vicar) on Aug 05, 2011 at 09:08 UTC |