Trouble with maths

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ady
Forum Newbie
Posts: 4
Joined: Fri Feb 17, 2006 6:38 am

Trouble with maths

Post by Ady »

Okay, I'm trying to do this:

Code: Select all

$func1=$var1/$var2;
$func2=$var3-$func1;
So it divides $var1 by $var2, then it takes that away from $var3, but for some reason it sets the $fun2 variable as "-$func1"... so it doesn't subtract, it just sets the $func variable with "-(whatever the number of $func)". Is there an error in the code that makes this happen?

Any help would be appreciated. :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$var3 equates to zero.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

are you sure that the values are being passed on? that may be the problem why you are not getting the correct answer you may want to.

This code seems to be right,make sure the values passed are also numbers.

Code: Select all

$var1=$_POST['number1'];//replace number 1 with the name of the field you want as var1.
$var2=$_POST['number2'];//replace with the name of the field.
$var3=$_POST['number3'];
/*replace with the name of the field that will hold the number you want to be subtracted from.*/

$func1=$var1/$var2; 
$func2=$var3-$func1;
the only thing i think that may be wrong in what i put is the firection of the slash(/)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

why don't you try echoing out your $var's and see what they are to ensure you're dealing with what you think you're dealing with....
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

burrito,your a genious haha 8O
Ady
Forum Newbie
Posts: 4
Joined: Fri Feb 17, 2006 6:38 am

Post by Ady »

Ah thanks for everyone's help, but I fixed the problem on my own. Thanks anyway. :D
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

its always good when people find their own SOULUTION :P 8O
Post Reply