0: #!/usr/bin/perl -w
1: # i know everyone has written a calculator.
2: # but im proud of this.
3: # its the first useful thing ive written.
4: # here we go
5:
6:
7: use strict;
8:
9: my $operation;
10: my $int;
11: my $int2;
12: my $answer;
13: my $runagain;
14:
15: calculator();
16:
17: sub calculator {
18: print "What operation (Add, Sub, Mult, Divd) do you want to do? ";
19: chomp($operation = <>);
20: print "Enter the first number: ";chomp($int = <>);
21: print "Enter the second number: ";chomp($int2 = <>);
22: if ($operation =~ /^a/) {
23: $answer = $int + $int2;
24: } elsif ($operation =~ /^s/) {
25: $answer = $int - $int2;
26: } elsif ($operation =~ /^m/) {
27: $answer = $int * $int2;
28: } elsif ($operation =~ /^d/) {
29: $answer = $int / $int2;
30: }
31: print "The answer is $answer\n";
32: print "Do you want to run this again? ";chomp($runagain = <>);
33: if ($runagain =~ /^y/) {
34: calculator();
35: } else {
36: print "goodbye\n";
37: }
38: }
In reply to Perl Calculator by gopher
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |