Answer to Question #306475 in UNIX/Linux Programming for panda

Question #306475
  1. Write a shell script to create a simple calculator.
1
Expert's answer
2022-03-08T07:11:11-0500

# !/bin/bash

 

# Take user Input

echo "Enter Two numbers : "

read a

read b

 

# Input type of operation

echo "Enter Choice :"

echo "1. Addition"

echo "2. Subtraction"

echo "3. Multiplication"

echo "4. Division"

read ch

 

# Switch Case to perform

# calculator operations

case $ch in

  1)res=`echo $a + $b | bc`

  ;;

  2)res=`echo $a - $b | bc`

  ;;

  3)res=`echo $a \* $b | bc`

  ;;

  4)res=`echo "scale=2; $a / $b" | bc`

  ;;

esac

echo "Result : $res"


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS