Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
* * * * * 1 votes

Bash Simple Calculator

bash

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1 YoungPythoner

YoungPythoner

    CC Newcomer

  • Member
  • PipPip
  • 17 posts

Posted 04 July 2015 - 05:36 AM

read -p "Write two number." n1 n2
echo "$n1 + $n2 = " + ("$n1 + $n2" | bc -l)
echo "$n1 - $n2 = " + ("$n1 - $n2" | bc -l)
echo "$n1 * $n2 = " + ("$n1 * $n2" | bc -l)
echo "$n1 / $n2 = " + ("$n1 / $n2" | bc -l)
read "Thanks for using."

I wrote this. Yeah...  Hope you like it!

First line taking data, echos are calculating datas and end line stopping to close program. Sorry for bad English.



#2 JonElias

JonElias

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 201 posts

Posted 18 July 2015 - 02:20 AM

so..

what is the problem in your code??


"computers are useless they only give you answers" Pablo Picasso
And yes he was alive when the first programmable computer was made

#3 watael

watael

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 31 July 2015 - 07:10 AM

hi,

 

the problem is command substitution to get the result of the command :

echo "$n1 + $n2 = $(echo "$n1 + $n2" | bc -l)"

though it's useless :

echo "print \"$n1 + $n2 = \"; $n1 + $n2" | bc -l