Skip to content

Commit 9cb5624

Browse files
Calculator.sh
This scripts evaluates two based on the user input and the user choice.
1 parent 1dbd99a commit 9cb5624

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

calculator.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
#This is a simple script to calculate two numbers.
4+
5+
# Taking user input
6+
7+
echo "Enter two numbers: "
8+
read a
9+
read b
10+
11+
#input type of operation
12+
13+
echo "Enter your choice: "
14+
echo "1. Addition"
15+
echo "2. Substraction"
16+
echo "3. Multiplication"
17+
echo "4. Division"
18+
read ch
19+
20+
#Acting on the user input
21+
22+
case $ch in
23+
1) res=`echo $a + $b | bc`
24+
;;
25+
2) res=`echo $a - $b | bc`
26+
;;
27+
3) res=`echo $a \* $b | bc`
28+
;;
29+
4) res=`echo "scale=2; $a / $b" | bc`
30+
;;
31+
esac
32+
33+
#Printing result
34+
echo "Result: $res"
35+
36+

0 commit comments

Comments
 (0)