Advertisement
TermSpar

Calculator Script

Jun 11th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.96 KB | None | 0 0
  1. print("---------------------------------------------------------\n");
  2. print("Welcome to Perl Calculator: By Ben Bollinger");
  3. print("\n---------------------------------------------------------\n");
  4.  
  5. my $first_num = 0;
  6. my $second_num = 0;
  7. my $operator;
  8.  
  9. print("Type first number: ");
  10. $first_num = <STDIN>;
  11.  
  12. print("\nType Operator (+, -, /, *):");
  13. $operator = <STDIN>;
  14.  
  15. print("\nType second number: ");
  16. $second_num = <STDIN>;
  17.  
  18.  
  19. calculate($first_num, $second_num, $operator);
  20.  
  21. sub calculate{
  22.     my ($f, $s, $o) = (@_);
  23.     my $final_value;
  24.     if($o eq "+\n"){
  25.         $final_value = $f + $s;
  26.         print("\nTotal value is: $final_value\n\n");
  27.     }elsif($o eq "-\n"){
  28.         $final_value = $f - $s;
  29.         print("\nTotal value is: $final_value\n\n");
  30.     }elsif($o eq "*\n"){
  31.         $final_value = $f * $s;
  32.         print("\nTotal value is: $final_value\n\n");
  33.     }elsif($o eq "/\n"){
  34.         $final_value = $f / $s;
  35.         print("\nTotal value is: $final_value\n\n");
  36.     }else{
  37.         print("\nInvalid\n\n");
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement