Simple addition script... - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Simple addition script...

I'm trying to write a script in Linux that allows the user to input 1 number, then a second number and outputs the addition of the two numbers!

The inputing of the numbers is fine but i cant seem to get them to be added...

Any help would be appreciated...

- Jonny

Comments

  • JonathanJonathan Posts: 2,914Member
    : I'm trying to write a script in Linux that allows the user to input 1 number, then a second number and outputs the addition of the two numbers!
    :
    : The inputing of the numbers is fine but i cant seem to get them to be added...
    :
    : Any help would be appreciated...
    :
    What langauge do you want the script in? If Perl will do...

    #!/usr/bin/perl
    $a = <>;
    $b = <>;
    chop $a;
    chop $b;
    print $a + $b . "
    ";

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • fleeballfleeball Posts: 47Member

    I dont know the language we're surposed to be scripting in but the first line should be

    #!/bin/sh

    - Jonny
  • XfactorXfactor Posts: 343Member
    :
    : I dont know the language we're surposed to be scripting in but the first line should be
    :
    : #!/bin/sh
    :
    : - Jonny

    This is called shell scripting.

    There are a couple of ways to do this. Use which ever one you like:

    [code]
    #!/bin/sh

    echo "enter two numbers"
    read a b

    c=$(($a+$b))
    echo "$a + $b = $c"

    # or

    let c="$a+$b"
    echo "$a + $b is $c"
    [/code]
  • fleeballfleeball Posts: 47Member
    : :
    : : I dont know the language we're surposed to be scripting in but the first line should be
    : :
    : : #!/bin/sh
    : :
    : : - Jonny
    :
    : This is called shell scripting.
    :
    : There are a couple of ways to do this. Use which ever one you like:
    :
    : [code]
    : #!/bin/sh
    :
    : echo "enter two numbers"
    : read a b
    :
    : c=$(($a+$b))
    : echo "$a + $b = $c"
    :
    : # or
    :
    : let c="$a+$b"
    : echo "$a + $b is $c"
    : [/code]
    :
    Cheers, i used the top 1 and its working fine...

    - Jonny
Sign In or Register to comment.