Jump to content

______This code is REALLY simple...why isn't it working?______


lotrfan

Recommended Posts

elseif ($positional_sum == "6") {
if ($number_of_angles == "1"){
echo "This triangle is SAS";}
elseif ($number_of_angles == "3") {
echo "This triangle is AAA.";}
	if (empty($side[0])){
	$side[0] = (sqrt((($side[1]*$side[1])+($side[2]*$side[2]))-(2*$side[1]*$side[2]*cos($angle[0])));}}

 

"Parse error: syntax error, unexpected '}' in C:\Program Files\Apache Group\Apache2\htdocs\hypotenuse.php on line 172"

 

Thanks in Advance.

elseif ($positional_sum == "6") {
if ($number_of_angles == "1"){
echo "This triangle is SAS";}
elseif ($number_of_angles == "3") {
echo "This triangle is AAA.";}
	if (empty($side[0])){
	$side[0] = (sqrt((($side[1]*$side[1])+($side[2]*$side[2]))-(2*$side[1]*$side[2]*cos($angle[0])));}}

 

The last line here (beginning with 'if(empty($side[0]))....etc') is line 172.

it must be because its cut.  any way i found it in line 173 of what it appears

$side[0] = (sqrt((($side[1]*$side[1])+($side[2]*$side[2]))-(2*$side[1]*$side[2]*cos($angle[0]))));}

 

u missed a ), but that isn't simple that is ugly.

u added a bracket at the last line before sqrt which caused the error:

 

replace :

 

$side[0] = (sqrt((($side[1]*$side[1])+($side[2]*$side[2]))-(2*$side[1]*$side[2]*cos($angle[0])));}}

 

with this:

 

<?php
$side[0] = sqrt((($side[1]*$side[1])+($side[2]*$side[2]))-(2*$side[1]*$side[2]*cos($angle[0])));}}
?>

another thing, please make sure your code is readable and properly indented like this :

 

<?php
elseif ($positional_sum == "6")
{
if ($number_of_angles == "1")
{
  echo "This triangle is SAS";
}
elseif ($number_of_angles == "3")
{
  echo "This triangle is AAA.";
}

if (empty($side[0]))
{
  $side[0] = sqrt((($side[1]*$side[1])+($side[2]*$side[2]))-(2*$side[1]*$side[2]*cos($angle[0])));
}
}
?>

 

isn't it better now, readability is important in coding...

no but if you doing math why not make a function p_theory

<?php
function p_theory($a,$b,$theda,$type){
//Angle is in radians
if($type == 1){
$theda = $theda;
}
//Angle is in degrees
else{
$theda = deg2rad($theda);
}
$value = sqrt(
				(pow($a,2)+pow($b,2))-
				(2*$a*$b*cos($theda))
			);
return $value;
}
?>

Makes sense? then its repeatable on other pages

Well, I was just trying to use the Law Of Cosines. I don't exactly understand what you're trying to explain. Is it to allow inputs in both degrees and radians? Because that would be helpful. Are PHP values automatically radians? I'm very sorry if these are dumb questions -- I just started PHP about a month ago. I'm loving it, but it's still a new thing for me.

 

Thanks once again...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.