Create a Number guessing game. Have the computer pick a number from 0-60 using t
ID: 3694967 • Letter: C
Question
Create a Number guessing game. Have the computer pick a number from 0-60 using the Random Number Generator I provided. Use the following code as the random number generator. #Random Number Generator RANGE=60 num=$RANDOM let "num %= $RANGE" echo $num #RANGE=60 sets the RANDOM number from 0-60 #the echo $num prints the number write bash script (Linux)Then allow the user to guess at the number until the user gets it right. Please include the following: a) Keep a counter of how many guesses were made, and then tell the user how many guesses it took. b) As the user guesses, tell the user whether the guess is too high or too low.
Explanation / Answer
MAXIMUMCOUNT=10
counter=1
while [ "$counter" -le $MAXIMUMCOUNT ]
do
num=$RANDOM
echo $num
let "counter += 1" # Increment the counter.
done
echo "-----------------"
RANGE=60
echo
num=$RANDOM
let "num %= $RANGE"
echo "Guess is too low"
FLOOR=100
num=0 #initialize num
while [ "$num" -le $FLOOR ]
do
num=$RANDOM
done
echo "Guess is too high"
echo
num=0 #initialize num
while [ "$num" -le $FLOOR ]
do
num=$RANDOM
let "num %= $RANGE"
done
echo "Guess is between range and floor"
echo
exit 0