answersLogoWhite

0


Best Answer

input="yes"

while [[ $input = "yes" ]]

do

echo "------------"

echo "Calculator"

echo "------------"

PS3="Press 1 for Addition, 2 for subtraction, 3 for multiplication and 4 for division: "

select math in Addition Subtraction Multiplication Division

do

case "$math" in

Addition)

echo "Enter first no:"

read num1

echo "Enter second no:"

read num2

result=<code>expr $num1 + $num2</code>

echo Answer: $result

break

;;

Subtraction)

echo "Enter first no:"

read num1

echo "Enter second no:"

read num2

result=<code>expr $num1 - $num2</code>

echo Answer: $result

break

;;

Multiplication)

echo "Enter first no:"

read num1

echo "Enter second no:"

read num2

result=<code>expr $num1 \* $num2</code>

echo Answer: $result

break

;;

Division)

echo "Enter first no:"

read num1

echo "Enter second no:"

read num2

result=$(expr "scale=2; $num1/$num2" | bc)

echo Answer = $result

break

;;

*)

echo Choose 1 to 4 only!!!!

break

;;

esac

done

echo "Do you want to calculate again(yes/no):"

read input

echo "Thank you for using this program"

done

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago
  1. Echo "Enter first number:"
  2. Read n1
  3. Echo "Enter Second number:"
  4. Read n2
  5. Echo "Enter operation to be carried out that is +, - , / or X"
  6. Read opr
  7. If [ opr=="+" ]
  8. Then
  9. echo $(( $a + $b ))
  10. elif [ opr=="-"]
  11. then
  12. echo $(( $a - $b ))
  13. elif [ opr=="/" ]
  14. then
  15. echo $(( $a / $b ))
  16. elif [ opr=="X" ]
  17. then
  18. echo $(( $a * $b ))
  19. fi
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a shell script to simulate a simple calculator program to perform addition substraction multiplication and division?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the 4 basic maths symbols?

Addition (+), Substraction (-), Division ( / ), and Multiplication ( x ).


What is the order of operations for solving math equations?

Parentheses Exponents Multiplication Division Addition Substraction


What is the definition of standard algorithm?

The definition of "standard algorithm" is that it is a mathematical method used to solve problems such as addition, substraction, division, and multiplication.


How would 2 pond 60 be shown on a calculator display?

The answer will depend on how the information was entered - in pounds (or ponds) or in pennies, what the operations were - addition/subtraction or -multiplication/division).The answer will depend on how the information was entered - in pounds (or ponds) or in pennies, what the operations were - addition/subtraction or -multiplication/division).The answer will depend on how the information was entered - in pounds (or ponds) or in pennies, what the operations were - addition/subtraction or -multiplication/division).The answer will depend on how the information was entered - in pounds (or ponds) or in pennies, what the operations were - addition/subtraction or -multiplication/division).


Function of abacus?

An abacus is an ancient form of the modern day calculator.


Is multiplication before division in order of operations?

"Parentheses, Exponents, Multiplication and Division, and Addition and Subtraction." Therefore multiplication and division are equal.


Where is the multiplication sign on a calculator?

above the - and below the division


The reverse of multiplication is?

Division


Subtraction is a form of addition and division is a form of multiplication give as example?

nope. Multiplication is a form of addition. Division is a form of subtraction.


What are the fundamental operation of math?

the fundamental operations in math are, addition +, subtraction -, division /,and multiplication x ..


What is the difference between the inverse of addition and the inverse of multiplication?

the inverse of addition is subtraction and the inverse of multiplication is division. Of course, multiplication is just repeated addition so division is just repeated subtraction!


What are advantages using calculator in teaching mathematics lesson?

Depending on the complexity of the calculation, a calculator can provide accurate answers more quickly.