Page 1 of 1

PHP for Maths

Posted: Wed Jun 01, 2005 4:07 am
by Parody
Hmm....

Any ideas what is wrong with this?:

Code: Select all

<?php
$weight = 3150;
$HP = 500;
$answer = (6.9446 X ($weight / $HP)^.2841);
print "$answer";
?>
I get this error:

Code: Select all

Parse error: syntax error, unexpected T_STRING in c:\program files\apache group\Apache\htdocs\mile.php on line 4
Thanks in advance :D

Posted: Wed Jun 01, 2005 4:11 am
by timvw
Please read chapther 15. Operators in the manual (http://www.php.net/manual). Please notice that the operator for multiplication is * instead of X.

Posted: Wed Jun 01, 2005 4:13 am
by Parody
Thanks, I'm tired :oops:

Posted: Wed Jun 01, 2005 4:21 am
by Parody
Ok, it works but its getting the wrong answer

This is the equation I am trying to use:
6.9446 X (weight / HP)^.2841

This is what I have:

Code: Select all

<?php
$weight = 3826;
$HP = 294;
$answer = (6.9446 * ($weight / $HP)^.2841);
print "$answer";
?>
According to the mathematical equation (not the php one) with the same values within weight and HP the answer is : 14.396

The PHP equation gets : 90.


I think it is the ^ . What does php interpret by this symbol?

Posted: Wed Jun 01, 2005 4:25 am
by timvw
RTFM.

Posted: Wed Jun 01, 2005 4:29 am
by Parody
Read the F***ing Manual?

I F***ing did, lol, sorry :oops:

This is what it says:

$a ^ $b Xor Bits that are set in $a or $b but not both are set.

And that means what?

That is the only time it is refrenced throughout the manual. :cry:

Posted: Wed Jun 01, 2005 4:30 am
by Ross2376
Use:

Code: Select all

<?php
$weight = 3826;
$HP = 294;
$answer = (6.9446 * pow(($weight / $HP), .2841));
print "$answer";
?>
The ^ does not mean raised to in PHP. Use the pow() function instead.

pow(base, exponent);

Posted: Wed Jun 01, 2005 4:33 am
by Parody
Thanks.

Posted: Wed Jun 01, 2005 1:46 pm
by wwwapu
Parody wrote:$a ^ $b Xor Bits that are set in $a or $b but not both are set.
And that means what?
This is basic logic, dear Watson. Search for "logic circuits" or "boolean algebra"
http://www.allaboutcircuits.com/vol_4/chpt_7/7.html is quite understandable explanation on xor.