oh me gooshers! I really need some help with PHP math!!!

Live forum: http://forum.freeipodguide.com/viewtopic.php?t=45968

cwncool

18-09-2006 20:10:19

ugggh. i get parse errors every time i run this script on the "solve variable"

The error is
[code16c04320fc0]Parse error: syntax error, unexpected '(' in /home/.chasm/cwncool/www.gigacat.com/corrsolve/solve.php on line 9[/code16c04320fc0]

and the script is
http//www.gigacat.com/corrsolve/solve.txt

It says there is a problem on line 9 with an unexpected '(' but I've checked it over a trillion times and I can't find it. ugggh. Can someone help me fix this? Thanx!

dmorris68

18-09-2006 20:23:24

The problem is obvious. )

[code1c1a0d24e83]$solvedec = (10($exy) - ($ex)($ey)) / (sqrt(10($ex2) - $exo2)) li (sqrt(10($ey2) - $eyo2));[/code1c1a0d24e83]

I'm assuming you intend to multiply 10 by those variables following it, and also the ($ex)($ey) pairs. You need to insert an asterisk 'li' to multiply.

This should do it

[code1c1a0d24e83]$solvedec = ((10 li $exy) - ($ex li $ey)) / (sqrt((10 li $ex2) - $exo2)) li (sqrt((10 li $ey2) - $eyo2));[/code1c1a0d24e83]

cwncool

18-09-2006 20:31:51

i inserted that in place of the line, and it still gives me an error, just a different one.


Parse error syntax error, unexpected T_ECHO, expecting ',' or ';' in /home/.chasm/cwncool/www.gigacat.com/corrsolve/solve.php on line 18

dmorris68

18-09-2006 20:34:42

Yeah, because you're missing a semicolon before 'echo $solvedec;'

[code18606eac20f]echo 'Decimal Answer:&nbsp;' echo $solvedec; echo '<br><br>';[/code18606eac20f]

Ya know, with both of these errors, it's telling you exactly what is wrong and where. ;)

BTW, if you're intending on coding for real, you should consider adopting some standard formatting guidelines. It's typically bad form to put multiple statements on one line, and in this case serves to hide the problem in line 18 -- it would have been more obvious had the lines been broken up. Also the extra echo's in this case are redundant anyway, you can do the following

[code18606eac20f]echo 'Decimal Answer:&nbsp;' . $solvedec . '<br><br>';[/code18606eac20f]

Actually, with PHP, you can embed the $solvedec inside the quotes and put it all in one big string if you want to, like so (you don't need the nonbreaking space entity code if you only inserting a single space)

[code18606eac20f]echo 'Decimal Answer: $solvedec<br><br>';[/code18606eac20f]

TryinToGetPaid

18-09-2006 20:37:21

I think you owe Dmorris dinner.

cwncool

18-09-2006 20:39:31

oh my gosh! hahaha! so dumb. lol. but that math you gave me doesnt' output the right answer

Nimh

18-09-2006 20:40:39

[quote8b0e24b2e5="TryinToGetPaid"]I think you owe Dmorris dinner.[/quote8b0e24b2e5]

It was funny, cuz I was just thinking something along the same lines, only dirty.

cwncool

18-09-2006 20:42:06

that math you gave me doesnt' output the right answer though... for my equation it should be outputting like .71 but it's giving me 2000 something

dmorris68

18-09-2006 20:46:15

[quotee5d7483c6c="cwncool"]that math you gave me doesnt' output the right answer though... for my equation it should be outputting like .71 but it's giving me 2000 something[/quotee5d7483c6c]
Well, I didn't write your equation, you did. ;) Nor did I error check it beyond syntax -- I just suggested the correct syntax to do what it appeared you were trying to do, i.e. multiply those values. You may have the parens in the wrong place or something. In programming languages (other than math languages like MathLab or something), you can't multiply like [be5d7483c6c]a(b)[/be5d7483c6c], you have to use the multiply operator, i.e. [be5d7483c6c]a li b[/be5d7483c6c] for PHP and other C-syntax based languages.

cwncool

18-09-2006 20:52:17

grrrr. lol. the equation is http//upload.wikimedia.org/math/5/f/3/5f31fa4b96c9f97ce1efa37e99e04457.png there. that's a bit different style but same thing. lol. i'll figure it out. thanx dmorris. you teh best.

EatChex89

20-09-2006 20:23:51

it looks better in Vista, because it's black glassy looking

cwncool

20-09-2006 20:24:37

[quote3c1bfd999d="EatChex89"]it looks better in Vista, because it's black glassy looking[/quote3c1bfd999d]
??? Did you reply in the wrong thread?