I am trying to create a calculator:
echo "What is your number?"
read n1
echo "what is your second number?"
read n2
echo "what do you want to do?"
echo "1. add"
echo "2. subtract"
echo "3. divide"
echo "4. multiply"
read ans
if
ans=$(( $n1+$n2 )); then
echo $ans
elif
ans=$(( $n1-$n2 )); then
echo $ans
elif
ans=$(( $n1/$n2 )); then
echo $ans
elif
ans=$(( $n1*$n2 )); then
echo $ans
else
But when I insert letters it shows me 0. How can I improve it? Also it gives me sometimes wrong answers.
$sign
variable anywhere... And you would be better off using acase
statement than all thatif..elif...
logic. – jasonwryan Jun 10 at 6:37