-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplecalculator.sh
69 lines (63 loc) · 1.66 KB
/
simplecalculator.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
#!/bin/bash
# Lucas Saito, 2021/04/04
# This is a basic calculator.
# It can perform addition, subtraction, multiplication
# and division of two number inputted by the user.
TOPBAR="|**********************************|"
BOTBAR="************************************"
EMPTYBAR="| |"
function print_head {
printf "$TOPBAR\n"
printf "| Welcome to Simple Calculator |\n"
printf "$BOTBAR\n"
printf "| Type the number of the operation:|\n"
printf "| 1- Sum |\n"
printf "| 2- Subtraction |\n"
printf "| 3- Multiplication |\n"
printf "| 4- Division |\n"
printf "$EMPTYBAR\n"
printf "$BOTBAR\n"
}
print_head
condition=0
while [[ $condition -eq 0 ]]
do
read operation
case $operation in
1)
printf "Sum selected.\nType the first number:\n"
read x
printf "Sum selected.\nType the second number:\n"
read y
printf "$x + $y = "
echo "scale=3; $x + $y" | bc
condition=1;;
2)
printf "Subtraction selected.\nType the first number:\n"
read x
printf "Subtraction selected.\nType the first number:\n"
read y
printf "$x - $y = "
echo "scale=3; $x - $y" | bc
condition=1;;
3)
printf "Multiplication selected.\nType the first number:\n"
read x
printf "Multiplication selected.\nType the first number:\n"
read y
printf "$x * $y = "
echo "scale=3; $x * $y" | bc
condition=1;;
4)
printf "Division selected.\nType the first number:\n"
read x
printf "Division selected.\nType the first number:\n"
read y
printf "$x / $y = "
echo "scale=3; $x / $y" | bc
condition=1;;
*)
print_head
echo "Invalid option, try again"
esac
done