Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: calculator script

by kiruthika.bkite (Scribe)
on Apr 29, 2010 at 04:12 UTC ( #837441=note: print w/replies, xml ) Need Help??

in reply to calculator script

The problem is ,in the following .
$nbArguments = $#ARGV + 1; print "number of arguments: $nbArgumentsn"; exit(1) unless $nbArguments == 5;

Here you are checking the number of arguments is five.
So it will fail if you are giving input in the following format.
1 + 2 3
So that time you need to check the number of arguments is equal to four.
If you want to give input like,
1 + 2 + 3
then that time you need to check the number of arguments is equal to five.And you need to change the following part of code also.
your code,
$a = $ARGV[0]; $operation = $ARGV[1]; $b = $ARGV[2]; $c = $ARGV[3]
Change into,
$val1 = $ARGV[0]; $operation1 = $ARGV[1]; $val2 = $ARGV[2]; $operation2 = $ARGV[3] $val3=$ARGV[4]

These changes are needed only in the case of if you are giving input in the format 1 + 2 + 3 .

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://837441]
LanX 1 ..2 ..3 ..4 .. is erix missing ;-)
LanX is Discipulus reciting "Springtime for Hitler" ?
[choroba]: erix could tell you how to do it in Postgres
[chacham]: wow, mysql really is as bad as i thougt
[choroba]: completion?
[LanX]: That's what he usually does when MySQL is mentioned ;-)
[chacham]: the same thing could be achieved with a trigger
[LanX]: choroba yes
chacham shudders at the thought of using a evil

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2017-03-30 15:10 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (360 votes). Check out past polls.