lotrfan Posted October 2, 2007 Share Posted October 2, 2007 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. Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/ Share on other sites More sharing options...
cooldude832 Posted October 2, 2007 Share Posted October 2, 2007 and what is line 172? Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-359741 Share on other sites More sharing options...
lotrfan Posted October 2, 2007 Author Share Posted October 2, 2007 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. Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-359744 Share on other sites More sharing options...
cooldude832 Posted October 2, 2007 Share Posted October 2, 2007 well it can't be because it doesn't have a } in it Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-359746 Share on other sites More sharing options...
lotrfan Posted October 2, 2007 Author Share Posted October 2, 2007 Really? Because there are 2 '}' in that line... I don't understand... The line is long so it wraps down to the next "line space" down, but it is still one line. Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-359748 Share on other sites More sharing options...
cooldude832 Posted October 2, 2007 Share Posted October 2, 2007 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. Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-359749 Share on other sites More sharing options...
jd2007 Posted October 2, 2007 Share Posted October 2, 2007 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])));}} ?> Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-359754 Share on other sites More sharing options...
lotrfan Posted October 2, 2007 Author Share Posted October 2, 2007 Oh, OK. I didn't know that the 'sqrt' function couldn't have a parentheses in front of it... And, yes, it is kind of ugly, but there is no other way to execute that kind of an operation...is there? Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-359760 Share on other sites More sharing options...
jd2007 Posted October 2, 2007 Share Posted October 2, 2007 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... Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-359761 Share on other sites More sharing options...
lotrfan Posted October 2, 2007 Author Share Posted October 2, 2007 Thanks. I'm new to PHP, so I really hadn't tried to get it clean like that, but it does help. Thanks for the quick response. Kudos to both of you for your help. Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-359762 Share on other sites More sharing options...
cooldude832 Posted October 2, 2007 Share Posted October 2, 2007 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 Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-359765 Share on other sites More sharing options...
lotrfan Posted October 3, 2007 Author Share Posted October 3, 2007 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... Link to comment https://forums.phpfreaks.com/topic/71463-______this-code-is-really-simplewhy-isnt-it-working______/#findComment-361291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.