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

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.