|
General Details
|
|
Perl
|
|
Posted 4.5 Years Ago
|
|
546 Views
|
|
Received 0 Ratings
|
|
Simple Calculator
Description
Can do simple sums. For example
1 + 1
Also can Square numbers.
5 * 5
Technical
When it asks you for what you would like to do, ie... 1. Add.
Enter the number,
Source Code
Comments
| Please login to post comments. |
|
|
Because i had problems with that mate.
|
|
|
Oh also... why have you used: if ($option eq 1)
eq is used for comparison of strings... just use == for numerical scalar comparison.
Kind regards,
Scott
|
|
|
Damn... thats a lot of code for a calculator... i just wrote this out in a minute and it can workout anything Perl can evaluate including variables (though they require my, remove use strict to get rid of that).
#!/usr/bin/perl -w
use strict;
#get the sum to evaluate
chomp(my $sum = <STDIN>);
#display it
print " = ";
eval "print $sum";
print "\n";
|
|
|
I see you've modified it. Much better!
Now how would you make i remember past sums such as the ability to do this kind of thing:
1 + 2 = 3
+ 2 = 5
- 3 = 2
Kind regards,
Scott
|
|
|
Whats
"This is a calculator. To Square a number. Only enter a number for number one. Leave two blank. \n Thank you!"
All about? My calculator does not say that *checks* lol.
Kind regards,
Scott
|
More "Perl" Source Codes By This Author
Recently Posted "Perl" Source Codes
Recently Rated "Perl" Source Codes
|