-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.sh
executable file
·96 lines (76 loc) · 1.7 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
Math_Addition () {
dialog --msgbox "${NUM_ONE} + ${NUM_TWO} = $(expr ${NUM_ONE} + ${NUM_TWO})" 5 50
Math_Loop
}
Math_Subtraction () {
dialog --msgbox "${NUM_ONE} - ${NUM_TWO} = $(expr ${NUM_ONE} - ${NUM_TWO})" 5 50
Math_Loop
}
Math_Multiplication () {
dialog --msgbox "${NUM_ONE} * ${NUM_TWO} = $(expr ${NUM_ONE} \* ${NUM_TWO})" 5 50
Math_Loop
}
Math_Division () {
dialog --msgbox "${NUM_ONE} / ${NUM_TWO} = $(expr ${NUM_ONE} / ${NUM_TWO})" 5 50
Math_Loop
}
Math_Loop () {
TRY=$(dialog --stdout --inputbox "Type \"exit\" to Exit" 0 0)
if [ "$TRY" == exit ]
then
echo "Bye!"
exit 3
else
Math_Start
exit 4
fi
}
Math_Start () {
NUM_ONE=$(dialog --stdout --nocancel --inputbox "Enter A Number" 0 50)
NUM_TWO=$(dialog --stdout --nocancel --inputbox "Enter A Number" 0 50)
if [ -z "$NUM_ONE" ]
then
dialog --msgbox "Insufficient Data to perform Mathematical Operation!" 5 70
exit 0
elif [ -z "$NUM_TWO" ]
then
dialog --msgbox "Insufficient Data to perform Mathematical Operation!" 5 70
exit 1
fi
OPR=$(dialog --stdout --nocancel --menu "Choose the Mathematical Operation: " 0 50 0 "1" "Addition" "2" "Subtraction" "3" "Multiplication" "4" "Division")
echo $OPR
case $OPR in
1)
# echo "Addition"
Math_Addition
;;
2)
# echo "Subt"
Math_Subtraction
;;
3)
# echo "mult"
Math_Multiplication
;;
4)
# echo "Div"
Math_Division
;;
*)
exit 2
;;
esac
}
Math_Start
Math_Loop () {
TRY=$(dialog --stdout --inputbox "Type \"exit\" to Exit" 0 0)
if [ "$TRY" == exit ]
then
echo "Bye!"
exit 3
else
Math_Start
exit 4
fi
}