I have a simple calculator script which I have been playing around with. At the moment it can work out two arguments. I'm trying to edit the script so it can work out three arguments. Please can someone help. Thanks
-------------------------#!/usr/bin/perl $nbArguments = $#ARGV + 1; print "number of arguments: $nbArgumentsn"; exit(1) unless $nbArguments == 3; $a = $ARGV[0]; $b = $ARGV[2]; $operation = $ARGV[1]; if ($operation eq "+") {$result = $a + $b; }elsif ($operation eq "-") {$result = $a - $b; }elsif ($operation eq "/") {$result = $a / $b; }elsif ($operation eq "x") {$result = $a * $b; }print "$a $operation $b = $result \n"; --------------------------------------- This is what I tried and failed! #!/usr/bin/perl $nbArguments = $#ARGV + 1; print "number of arguments: $nbArgumentsn"; exit(1) unless $nbArguments == 5; $a = $ARGV[0]; $operation = $ARGV[1]; $b = $ARGV[2]; $c = $ARGV[3]; if ($operation eq "+") {$result = $a + $b + $c; }elsif ($operation eq "-") {$result = $a - $b; }elsif ($operation eq "/") {$result = $a / $b; }elsif ($operation eq "x") {$result = $a * $b; }print "$a $operation $b $operation $c = $result \n";
In reply to calculator script by Nathan_84
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |