PERL calcultor , help needed

Discussion in 'Programming' started by botas84, Mar 17, 2008.

  1. #1
    I have to make a perl calculator for my class that asks if the use wants to add or mutiply . and so far . this is the only this i have

    print " Now im going to add 2 numbers . \n" ;
    print " What 2 numbers do you want to add ?" ;
    print "\n" ;
    chomp( $firstnumber=<>) ;
    print "what is the second number you want to add ? \n " ;
    chomp( $secondnumber=<>) ;
    $result= $firstnumber + $secondnumber ;
    print "when you add firstnumber and $secondnumber the result is $ result \n" ;



    now i have to add a IF statement to the calculator and add multiplication to it . so can some one plz show me how to use a IF statements in perl . and accept the user when they tell me what they want to do...:)
     
    botas84, Mar 17, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    Tizag on how to use IF statements.
    http://www.tizag.com/perlT/perlif.php

    Here's a quick modification.

    print "Enter m to multiply, any other key to add. \n";
    chomp($operation = <>);
    print " What is the first number ?" ;
    print "\n" ;
    chomp( $firstnumber=<>) ;
    print "Enter second number? \n " ;
    chomp( $secondnumber=<>) ;

    if ($operation eq "m") {
    $result = $firstnumber * $secondnumber;
    $operation_text = '*';
    }
    else {
    $result= $firstnumber + $secondnumber ;
    $operation_text = '+';
    }

    print "$firstnumber $operation_text $secondnumber = $result";
     
    shallowink, Mar 17, 2008 IP
  3. botas84

    botas84 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    And one more question . i only used perl at school and we open it with " perl command line interpreter " does any1 know where i can get it
     
    botas84, Mar 17, 2008 IP
  4. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #4
    shallowink, Mar 17, 2008 IP
  5. botas84

    botas84 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks . you were very helpful
     
    botas84, Mar 17, 2008 IP
  6. botas84

    botas84 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    but . which one files on the website should i download
     
    botas84, Mar 17, 2008 IP
  7. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #7
    shallowink, Mar 17, 2008 IP
  8. botas84

    botas84 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    after i download it .. which file do i open . it is a rar file
     
    botas84, Mar 17, 2008 IP
  9. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #9
    shallowink, Mar 17, 2008 IP
  10. botas84

    botas84 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    i have windows vista .. which one should i pick
     
    botas84, Mar 17, 2008 IP
  11. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
  12. botas84

    botas84 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Thank you very mucH!!!!
     
    botas84, Mar 17, 2008 IP