-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsc9.sh
More file actions
46 lines (38 loc) · 718 Bytes
/
sc9.sh
File metadata and controls
46 lines (38 loc) · 718 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
#!/bin/bash
# Function definitions
add() {
echo "Result: $(( $1 + $2 ))"
}
subtract() {
echo "Result: $(( $1 - $2 ))"
}
multiply() {
echo "Result: $(( $1 * $2 ))"
}
divide() {
if [ "$2" -eq 0 ]; then
echo "Error: Division by zero not allowed"
else
echo "Result: $(( $1 / $2 ))"
fi
}
# User input
echo "Enter first number:"
read a
echo "Enter second number:"
read b
echo
echo "Choose operation:"
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
read choice
# Decision based on user choice
case $choice in
1) add $a $b ;;
2) subtract $a $b ;;
3) multiply $a $b ;;
4) divide $a $b ;;
*) echo "Invalid choice" ;;
esac