LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-02-2003, 02:55 PM   #1
Dimitris
LQ Newbie
 
Registered: Aug 2003
Posts: 13

Rep: Reputation: 0
Can you find the error ? (160 lines) math-cases etc


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
 
Old 09-02-2003, 03:16 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I've only had a quick look but looking around the line number and the blocks involved it looks like hte problem is with this line:
x=$(( ( $b+$c > / $a ))#NEED TO BE DECIMAL!
 
Old 09-02-2003, 03:30 PM   #3
Dimitris
LQ Newbie
 
Registered: Aug 2003
Posts: 13

Original Poster
Rep: Reputation: 0
Oh thanks the mistake was a bit stupid , well another problem that I have is that the generated result in the second part of the program is that it doesn't give a decimal.

How to make it show the decimal ?

Thanks again for the help!
 
Old 09-02-2003, 03:35 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Sorry I don't really know what you mean by the second part o fthe program. Can you post what it does say (including all output) and what you want it to say.
 
Old 09-02-2003, 03:53 PM   #5
Dimitris
LQ Newbie
 
Registered: Aug 2003
Posts: 13

Original Poster
Rep: Reputation: 0
I mean after the

##################################

that's the second part when it calculater the simple equation.
It does return an integer (1,2,3 etc...) not deciman when needed!

That's my last problem I guess.

Thanks,
Jim
 
Old 09-02-2003, 04:42 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You can use bc. Calculate x like:
x=`echo "1+2/5" | bc -l`;
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Two million error lines in .xsession-error file from FireFox acanton Linux - Software 4 08-28-2005 09:53 AM
Help, help! How to find lines in between searched patterns? wujee Linux - Software 1 01-06-2005 02:52 PM
vi command to find and delete all lines beginning with a character geomatt Linux - Software 8 12-20-2004 03:30 AM
[c shell] How do I find how many lines a file has? saiz66 Programming 5 10-08-2004 03:01 PM
math overflow error tda Programming 12 04-03-2003 10:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration