So yes I am doing this for school but I have most of the script written. I don't know what's going on with it, maybe a syntax error but it keeps messing up(or I do).
The first issue is that it keeps posting the number that you are trying to guess and it says no file or directory(I didn't think I was calling for such things). The 86 is the current random number.
./random: line 14: 86: No such file or directory
The second issue is that the program is telling me guesses are always too low(I can also get them to always be too high)
I'm thinking of a number between 1 and 100. Your guess:6
./random: line 14: 86: No such file or directory
Sorry, your guess is too low. New guess:87
./random: line 14: 86: No such file or directory
Sorry, your guess is too low. New guess:
Here is my code:
#!/bin/bash
n1=$[($RANDOM % 100) +1]
guesses=1
echo -n "I'm thinking of a number between 1 and 100. Your guess:"
while read n2; do
if [ $n2 = $n1 ]; then
break;
else
echo
if [ $n2 < $n1 ]; then
echo -n "Sorry, your guess is too high. New guess:"
elif [ $n2 > $n1]; then
echo -n "Sorry, your guess is too low. New guess:"
fi
fi
guesses=$((guesses+1))
done
echo
echo "Good job! It took you $guesses guesses to get the right number."
Thanks in advance.