Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("---------------------------------------------------------\n");
- print("Welcome to Perl Calculator: By Ben Bollinger");
- print("\n---------------------------------------------------------\n");
- my $first_num = 0;
- my $second_num = 0;
- my $operator;
- print("Type first number: ");
- $first_num = <STDIN>;
- print("\nType Operator (+, -, /, *):");
- $operator = <STDIN>;
- print("\nType second number: ");
- $second_num = <STDIN>;
- calculate($first_num, $second_num, $operator);
- sub calculate{
- my ($f, $s, $o) = (@_);
- my $final_value;
- if($o eq "+\n"){
- $final_value = $f + $s;
- print("\nTotal value is: $final_value\n\n");
- }elsif($o eq "-\n"){
- $final_value = $f - $s;
- print("\nTotal value is: $final_value\n\n");
- }elsif($o eq "*\n"){
- $final_value = $f * $s;
- print("\nTotal value is: $final_value\n\n");
- }elsif($o eq "/\n"){
- $final_value = $f / $s;
- print("\nTotal value is: $final_value\n\n");
- }else{
- print("\nInvalid\n\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement