-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_2_findMagicNo.sh
More file actions
39 lines (32 loc) · 968 Bytes
/
02_2_findMagicNo.sh
File metadata and controls
39 lines (32 loc) · 968 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
#!/bin/bash
echo "Finding Magic Number"
echo "Think of a Number between 1 to 100"
maxRange=101
minRange=1
userNumber=0
userChoice=0
LESS_THAN=0
GREATER_THAN=1
EQUAL=2
while [ $userChoice -lt 2 ]
do
userNumber=$(( (maxRange + minRange) / 2 ))
echo "Is your number is $userNumber"
echo "Enter 0 if number is less than your Number"
echo "Enter 1 if number is greater than your Number"
echo "Enter 2 if number is equal to your Number"
read -p "Enter Choice (0-2) : " userChoice
case $userChoice in
$LESS_THAN)
maxRange=$userNumber
minRange=$minRange
;;
$GREATER_THAN)
maxRange=$maxRange
minRange=$userNumber
;;
$EQUAL)
echo "I GUESSED YOUR NUMBER"
;;
esac
done