wats wrong with this code? cause whenever i try and use it it doesnt display $H.

<?php
$_POST["xtwo"]=$A;
$_POST["xone"]=$B;
$A+$B=$C;
$C*$C=$D;
$_POST["ytwo"]=$E;
$_POST["yone"]=$F;
$E+$F=$G;
$G*$G=$H;
echo "The distance is: $H"
?>

and some of you might have known that im trying to do the distanceforumla
(x2-x1)^2+(y2-y1)^2=distance.
like finding the distance from these points (15,20) and (45,70)

you are doing the assignments in the reverse order.

When you are assigning a vaule to a variable, you must put the variable first, followed by an equal sign, followed by the value that you are assigning. Take the code:

$_POST["xtwo"]=$A;

This doesn't assign anything to $A, but attempts to assign a null to $_POST["xtwo"].

The reason your code doesn't output $H is because $H is blank at the end. Nothing is ever assigned to it. I suggest that you switch around your assignments in that code (all of them, not just for the $H), meaning put what you are assigning to on the left instead of right, and the value you are assigning on the right, instead of left.

you are doing the assignments in the reverse order.

When you are assigning a vaule to a variable, you must put the variable first, followed by an equal sign, followed by the value that you are assigning. Take the code:

$_POST["xtwo"]=$A;

This doesn't assign anything to $A, but attempts to assign a null to $_POST["xtwo"].

The reason your code doesn't output $H is because $H is blank at the end. Nothing is ever assigned to it. I suggest that you switch around your assignments in that code (all of them, not just for the $H), meaning put what you are assigning to on the left instead of right, and the value you are assigning on the right, instead of left.

thanks! ok ifixed it and now i get 28 for this problem idk what's wrong with it though when it should be like 12.32.

<?php
$A=$_POST["xtwo"];
$B=$_POST["xone"];
$C=($A-$B);
$D=($C*$C);
$E=$_POST["ytwo"];
$F=$_POST["yone"];
$G=($E-$F);
$H=($G*$G);
$I=sqrt($H);
echo "The distance is: $I";
?>

Shouldn't it be sqrt((x2-x1)^2+(y2-y1)^2)=distance ? You are just taking the sqrt of $H and not $H + $D.

Shouldn't it be sqrt((x2-x1)^2+(y2-y1)^2)=distance ? You are just taking the sqrt of $H and not $H + $D.

zomg!! thanks soo much dude!!!! :D!!
my last question is why do i get 13.8924439894 instead of 12.2882057 when i run it?
(24,15) and (36,8)

finding the distance from these points (15,20) and (45,70) Considering 15 as x1, 20 as y1, 45 as x2 and 70 as y2, if we apply the formula, it is, sqrt((45 - 15)^2 + (70-20)^2) = 58.3095189485 :-/

<?php
$A=45;
$B=15;
$C=($A-$B);
$D=($C*$C);
$E=70;
$F=20;
$G=($E-$F);
$H=($G*$G);
$I=sqrt($D+$H);
echo "The distance is: $I";
?>

The above program also gives the same output !

finding the distance from these points (15,20) and (45,70) Considering 15 as x1, 20 as y1, 45 as x2 and 70 as y2, if we apply the formula, it is, sqrt((45 - 15)^2 + (70-20)^2) = 58.3095189485 :-/

<?php
$A=45;
$B=15;
$C=($A-$B);
$D=($C*$C);
$E=70;
$F=20;
$G=($E-$F);
$H=($G*$G);
$I=sqrt($D+$H);
echo "The distance is: $I";
?>

The above program also gives the same output !

go here and put in the points:
http://math.pspstuff.elementfx.com/program.html
i used the code and type in 24,36,15,8 and i get 13 but when i do the problem manually i get 12.2882057. why is that?

Well, you are doing it wrong then. Because,
distance ^2 = (24-36)^2 + (15-8)^2
distance ^ 2 = (-12)^2 + (7)^2
distance ^ 2 = 144 + 49
distance ^ 2 = 193.
distance = sqrt ( 193)
distance = 13.89...

This question has already been answered. Start a new discussion instead.