Hello,
I would be pleased if you could help me as fast as possible to fix the code. I gives an error
./theproject.txt: line 138: syntax error near unexpected token `;;'
./theproject.txt: line 138: `;;'
Script :
#!/bin/bash
RANDOM=$$
let a=`expr $RANDOM % 10`
let b=`expr $RANDOM % 10`
let c=`expr $RANDOM % 10`
echo "Please enter your age:"
read age
if (( $age > 18 ))
then
echo "Generating equation..."
sleep 1
d=$(($b*$b-4*$a*$c))
if (($d<0))
then
echo "Square root is negative, equation can not be solved."
echo "Another equation will be generated for you."
./theproject.txt
fi
#z=`echo "sqrt ($b^2-4*$a*$c)" | bc -l`
#x=(-$b+$z)/2*$a
x=`echo "sqrt ( ( -$b+$d ) /2*$a )" | bc -l`
echo "Equation: " $a*x^2 + $b*x + $c
PS3="Can you solve the equation above?"
select choice in 'Yes' 'I need some help' 'No' 'Exit'
do
case $REPLY in
1)
echo "Please enter the number"
read result
if (($result==$x))
then
echo "Congratulations, you made it!"
exit 1
else
PS3="Would you like to try again?"
select choice in 'Yes' 'No'
do
case $REPLY in
1)./theproject.txt
;;
2) exit 1
;;
esac
done
fi
;;
2)
echo "To solve a quadratic equation you got to use the following formula:"
echo "(-b+-sqrt(b^2-4*a*c))/2*a"
sleep 1
PS3="Would you like to try again?"
select choice in 'Yes' 'No'
do
case $REPLY in
1)./theproject.txt
;;
2)exit 1
;;
esac
done
;;
3)
echo "It seems you can't solve it...well anyway the result is:"
d=$(($b*$b-4*$a*$c))
if (($d<0));
then
echo "D is negative, equation can not be solved!"
elif (($d==0));then
x=$((-$b/2*$a));
echo "D is equal to zero, the result is: "$x
exit 1
else
##z=`echo "sqrt ($b^$b-4*$a*$c)" | bc -l`
x=`echo "sqrt ( ( -$b+$d ) /2*$a )" | bc -l`
##x=(-$b+$z)/2*$a
echo "The two results of the equation are: "$x
fi
;;
4)
exit 1
;;
esac
done
##fi
##################################################################
else
##if (( $age < 18 ))
##then
x=$(( ( $b+$c > / $a ))#NEED TO BE DECIMAL!
echo "Generating equation..."
sleep 1
echo "Equation: " $a*x=$b+$c
PS3="Can you solve the equation above?"
select choice in 'Yes' 'I need some help' 'No' 'Exit'
do
case $REPLY in
1)
echo "Please enter the results: "
read results
if (( $results==$x ))
then
echo "Congratulations you made it!"
else
PS3="Would you like to try again?"
select choice in 'Yes' 'No'
do
case $REPLY in
1)./theproject.txt
;;
2)exit 1
;;
esac
done
fi
;;
2)
echo "To solve that kind of equation you just have to have some basic
knowledge of algebra. There is nothing else to say that go read how to
multiply and divide."
PS3="Would you like to try again?"
select choice in 'Yes' 'No'
do
case $REPLY in
1)./theproject.txt
;;
2)exit 1
;;
esac
done
;;
3)
echo "It seems you can't solve it...well anyway the result is: "
echo $x
;;
4)
exit 1
;;
esac
done
fi
Thanks ALOT for the help,
Please try it out and give me an answer if possible,
I would really appreciate it if fast
Bye