LINUX programming

Moderators: ITA
Number of threads: 1347
Number of posts: 2935

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Simple addition script... Posted by fleeball on 6 Oct 2004 at 5:50 AM
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
Report
Re: Simple addition script... Posted by Jonathan on 6 Oct 2004 at 6:47 AM
: 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 . "\n";

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.");

Report
Re: Simple addition script... Posted by fleeball on 6 Oct 2004 at 10:43 AM

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

#!/bin/sh

- Jonny
Report
Re: Simple addition script... Posted by Xfactor on 7 Oct 2004 at 2:12 AM
:
: 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:

#!/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"

Report
Re: Simple addition script... Posted by fleeball on 7 Oct 2004 at 8:16 AM
: :
: : 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:
:
:
: #!/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"
: 

:
Cheers, i used the top 1 and its working fine...

- Jonny



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.