#!/bin/bash count=1 while [ $count -lt 200 ] do echo \"Please gues the random nu
ID: 3695163 • Letter: #
Question
#!/bin/bash
count=1
while [ $count -lt 200 ]
do
echo "Please gues the random number between 0 and 60 computer has chosen for you:"
read number
RANGE=60
num=$RANDOM
let "num %= $RANGE"
echo $num
if [ $number -lt 0 ]
then
echo "Your number has to be between 0 and 60"
elif [ $number -gt 60 ]
then
echo "Your number has to be between 0 and 60"
elif [ $number -gt $num ]
then
echo "Guess is too high"
elif [ $number -lt $num ]
then
echo "Your guess is too high."
elif [ $number == $num ]
then
echo "You got it!"
echo and took you only $counter times.
count=`expr $count + 1`
done
the idea is to get a random number from 0-60 and have the user guess what it is, every time then input is made hint will be given whether the guess is too low or high and when the guess is right it is confirmed with number of attempts made ....here is what I got so far....
Explanation / Answer
Hi, I have corrected the given code. It is working fine. Please test it.
#!/bin/bash
count=1
while [ $count -lt 200 ]
do
echo "Please gues the random number between 0 and 60 computer has chosen for you:"
read number
RANGE=60
num=$RANDOM
let "num %= $RANGE"
echo $num
if [ $number -lt 0 ]
then
echo "Your number has to be between 0 and 60"
elif [ $number -gt 60 ]
then
echo "Your number has to be between 0 and 60"
elif [ $number -gt $num ]
then
echo "Your Guess is too high"
elif [ $number -lt $num ]
then
echo "Your guess is too low."
elif [ $number == $num ]
then
echo "You got it! and took you only $counter times."
fi
count=`expr $count + 1`
done
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.