Advertisement
TermSpar

Subroutines

Jun 12th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.59 KB | None | 0 0
  1. sub add_nums{
  2.   my ($num1, $num2) = @_;
  3.   my $total_value = $num1 + $num2;
  4.   print("$num1 + $num2 is $total_value");
  5. }
  6.  
  7. my $num_1;
  8. my $num_2;
  9.  
  10. print("Enter First Value: ");
  11. $num_1 = <STDIN>;
  12. chomp($num_1);
  13.  
  14. print("Enter Second Value: ");
  15. $num_2 = <STDIN>;
  16. chomp($num_2);
  17.  
  18. add_nums($num_1, $num_2);
  19.  
  20. sub oddOrEven{
  21.   my ($num) = @_;
  22.   my $remainder = $num % 2;
  23.  
  24.   if($remainder == 0){
  25.     print("$num is even");
  26.   }else{
  27.     print("$num is odd");
  28.   }
  29. }
  30.  
  31. my $user_num;
  32.  
  33. print("\nEnter Value To Check: ");
  34. $user_num = <STDIN>;
  35. chomp($user_num);
  36.  
  37. oddOrEven($user_num);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement