-
Notifications
You must be signed in to change notification settings - Fork 0
/
question1.sh
executable file
·59 lines (57 loc) · 1.56 KB
/
question1.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
#!/bin/bash
#Group Members
#Luisa Aimoli 10169687
#Braedan Robinson 10188414
#Quentin Petraroia 10145835
reg=[0-9]
while true; do
read -p "please enter a number: " num
if ! [[ $num =~ $reg ]] ; then
echo "Please enter a real number"
else
break
fi
if [[ $num == ":q" ]] ; then
echo "thanks for using the calculator"
exit 1
fi
done
total=$num
while true; do
read -p "enter a operation: " operation
if [[ $operation == ":q" ]] ; then
echo "thanks for using the calculator"
break
fi
if [[ $operation != "+" && $operation != "-" && $operation != "*" && $operation != "/" ]]
then
echo "Please enter a valid input"
continue
fi
read -p "enter a number again: " num1
if [[ $num1 == ":q" ]]; then
echo "thanks for using the calculator"
break
fi
if ! [[ $num1 =~ $reg ]] ; then
echo "Please enter a real number"
continue
fi
if [[ $operation == "+" ]]
then
total=$((total + num1))
echo "The result so far is: " $total
elif [[ $operation == "-" ]]
then
total=$((total - num1))
echo "The result so far is: " $total
elif [[ $operation == "*" ]]
then
total=$((total * num1))
echo "The result so far is: " $total
elif [[ $operation == "/" ]]
then
total=$((total / num1))
echo "The result so far is: " $total
fi
done