-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.sh
40 lines (35 loc) · 912 Bytes
/
calculator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
while true
do
read -p "Enter first number: " num1
read -p "Enter operation (+, -, *, /): " operation
read -p "Enter second number: " num2
case $operation in
"+")
result=$(echo "$num1 + $num2" | bc)
;;
"-")
result=$(echo "$num1 - $num2" | bc)
;;
"*")
result=$(echo "$num1 * $num2" | bc)
;;
"/")
if [ "$num2" -eq 0 ]; then
echo "Error: Division by zero"
continue
fi
result=$(echo "$num1 / $num2" | bc)
;;
*)
echo "Error: Unsupported operation"
continue
;;
esac
echo "Result: $result"
read -p "Do you want to perform another calculation? (y/n): " continueCalc
if [ "$continueCalc" != "y" ]; then
break
fi
done
echo "Goodbye!"