-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculater.sh
More file actions
51 lines (39 loc) · 801 Bytes
/
calculater.sh
File metadata and controls
51 lines (39 loc) · 801 Bytes
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
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Function for Addition
add() {
echo "Result: $(($1 + $2))"
}
# Function for Subtraction
sub() {
echo "Result: $(($1 - $2))"
}
# Function for Multiplication
mul() {
echo "Result: $(($1 * $2))"
}
# Function for Division
div() {
if [ $2 -eq 0 ]; then
echo "Error: Division by zero not allowed!"
else
echo "Result: $(($1 / $2))"
fi
}
echo "------ Calculator Using Shell Script ------"
echo "Enter first number:"
read num1
echo "Enter second number:"
read num2
echo "Choose operation:"
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
read choice
case $choice in
1) add $num1 $num2 ;;
2) sub $num1 $num2 ;;
3) mul $num1 $num2 ;;
4) div $num1 $num2 ;;
*) echo "Invalid choice!" ;;
esac