sheep01 Posted July 15, 2007 Share Posted July 15, 2007 Parse error: syntax error, unexpected $end in /home/rhqstaff/public_html/Sheep01/math/quad.php on line 43 <?php $a= $_POST['a']; $b= $_POST['b']; $c= $_POST['c']; function quadratic ($a, $b, $c, $root) { { $precision = 3; // Change this value for a different decimal places rounding. $bsmfac = $b*$b-4*$a*$c; if ($bsmfac < 0) { // Accounts for complex roots. $plusminusone = " + "; $plusminustwo = " - "; $bsmfac *=-1; $complex=(sqrt($bsmfac)/(2*$a)); if ($a < 0){ //if negative imaginary term, tidies appearance. $plusminustwo = " + "; $plusminusone = " - "; $complex *= -1; } // End if ($a < 0) $lambdaone = round(-$b/(2*$a), $precision).$plusminusone.round($complex, $precision).'i'; $lambdatwo = round(-$b/(2*$a), $precision).$plusminustwo.round($complex, $precision).'i'; } // End if ($bsmfac < 0) else if ($bsmfac == 0) { $lambdaone = round(-$b/(2*$a), $precision); $lambdatwo = round(-$b/(2*$a), $precision); } // End else if (bsmfac == 0) else { $lambdaone = (-$b+sqrt($bsmfac))/(2*$a); $lambdaone = round($lambdaone, $precision); $lambdatwo = (-$b-sqrt($bsmfac))/(2*$a); $lambdatwo = round($lambdatwo, $precision); } ( if ($root == 'root1') {return $lambdaone;} if ($root == 'root2') {return $lambdatwo;} if ($root == 'both') {return $lambdaone. ' and ' .$lambdatwo;} } // End function ?> ??? Quote Link to comment Share on other sites More sharing options...
infid3l Posted July 15, 2007 Share Posted July 15, 2007 function quadratic ($a, $b, $c, $root) { Quote Link to comment Share on other sites More sharing options...
sheep01 Posted July 15, 2007 Author Share Posted July 15, 2007 that worked, but now i get this weird error. This is just not my day... Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 If you are simply trying to use the function, and not create it, this is what your code should be: quadratic ($a, $b, $c, $root); that worked, but now i get this weird error. This is just not my day... What is the error? Quote Link to comment Share on other sites More sharing options...
sheep01 Posted July 15, 2007 Author Share Posted July 15, 2007 Parse error: syntax error, unexpected $end in /home/rhqstaff/public_html/Sheep01/math/quad.php on line 43 Quote Link to comment Share on other sites More sharing options...
infid3l Posted July 15, 2007 Share Posted July 15, 2007 <?php $a= $_POST['a']; $b= $_POST['b']; $c= $_POST['c']; function quadratic ($a, $b, $c, $root) { { $precision = 3; // Change this value for a different decimal places rounding. $bsmfac = $b*$b-4*$a*$c; if ($bsmfac < 0) { // Accounts for complex roots. $plusminusone = " + "; $plusminustwo = " - "; $bsmfac *=-1; $complex=(sqrt($bsmfac)/(2*$a)); if ($a < 0){ //if negative imaginary term, tidies appearance. $plusminustwo = " + "; $plusminusone = " - "; $complex *= -1; } // End if ($a < 0) $lambdaone = round(-$b/(2*$a), $precision).$plusminusone.round($complex, $precision).'i'; $lambdatwo = round(-$b/(2*$a), $precision).$plusminustwo.round($complex, $precision).'i'; } // End if ($bsmfac < 0) else if ($bsmfac == 0) { $lambdaone = round(-$b/(2*$a), $precision); $lambdatwo = round(-$b/(2*$a), $precision); } // End else if (bsmfac == 0) else { $lambdaone = (-$b+sqrt($bsmfac))/(2*$a); $lambdaone = round($lambdaone, $precision); $lambdatwo = (-$b-sqrt($bsmfac))/(2*$a); $lambdatwo = round($lambdatwo, $precision); } if ($root == 'root1') {return $lambdaone;} if ($root == 'root2') {return $lambdatwo;} if ($root == 'both') {return $lambdaone. ' and ' .$lambdatwo;} } // End function ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 Change your code to this: <?php $a= $_POST['a']; $b= $_POST['b']; $c= $_POST['c']; function quadratic ($a, $b, $c, $root) { $precision = 3; // Change this value for a different decimal places rounding. $bsmfac = $b*$b-4*$a*$c; if ($bsmfac < 0) { // Accounts for complex roots. $plusminusone = " + "; $plusminustwo = " - "; $bsmfac *=-1; $complex=(sqrt($bsmfac)/(2*$a)); if ($a < 0){ //if negative imaginary term, tidies appearance. $plusminustwo = " + "; $plusminusone = " - "; $complex *= -1; } // End if ($a < 0) $lambdaone = round(-$b/(2*$a), $precision).$plusminusone.round($complex, $precision).'i'; $lambdatwo = round(-$b/(2*$a), $precision).$plusminustwo.round($complex, $precision).'i'; } // End if ($bsmfac < 0) else if ($bsmfac == 0) { $lambdaone = round(-$b/(2*$a), $precision); $lambdatwo = round(-$b/(2*$a), $precision); } // End else if (bsmfac == 0) else { $lambdaone = (-$b+sqrt($bsmfac))/(2*$a); $lambdaone = round($lambdaone, $precision); $lambdatwo = (-$b-sqrt($bsmfac))/(2*$a); $lambdatwo = round($lambdatwo, $precision); } ( if ($root == 'root1') {return $lambdaone;} if ($root == 'root2') {return $lambdatwo;} if ($root == 'both') {return $lambdaone. ' and ' .$lambdatwo;} } // End function ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 Oops, I just found another error in your code. This should work: <?php $a= $_POST['a']; $b= $_POST['b']; $c= $_POST['c']; function quadratic ($a, $b, $c, $root) { $precision = 3; // Change this value for a different decimal places rounding. $bsmfac = $b*$b-4*$a*$c; if ($bsmfac < 0) { // Accounts for complex roots. $plusminusone = " + "; $plusminustwo = " - "; $bsmfac *=-1; $complex=(sqrt($bsmfac)/(2*$a)); if ($a < 0){ //if negative imaginary term, tidies appearance. $plusminustwo = " + "; $plusminusone = " - "; $complex *= -1; } // End if ($a < 0) $lambdaone = round(-$b/(2*$a), $precision).$plusminusone.round($complex, $precision).'i'; $lambdatwo = round(-$b/(2*$a), $precision).$plusminustwo.round($complex, $precision).'i'; } // End if ($bsmfac < 0) else if ($bsmfac == 0) { $lambdaone = round(-$b/(2*$a), $precision); $lambdatwo = round(-$b/(2*$a), $precision); } // End else if (bsmfac == 0) else { $lambdaone = (-$b+sqrt($bsmfac))/(2*$a); $lambdaone = round($lambdaone, $precision); $lambdatwo = (-$b-sqrt($bsmfac))/(2*$a); $lambdatwo = round($lambdatwo, $precision); } if ($root == 'root1') {return $lambdaone;} if ($root == 'root2') {return $lambdatwo;} if ($root == 'both') {return $lambdaone. ' and ' .$lambdatwo;} } // End function ?> Quote Link to comment Share on other sites More sharing options...
infid3l Posted July 15, 2007 Share Posted July 15, 2007 I just posted that two replies up... Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 I just posted that two replies up... Your code gives an error. Parse error: syntax error, unexpected $end in C:\Documents and Settings\My Documents\xampp\htdocs\index.php on line 42 the code I supplied shouldn't give one, I tested it. Quote Link to comment Share on other sites More sharing options...
infid3l Posted July 15, 2007 Share Posted July 15, 2007 I just posted that two replies up... Your code gives an error. Parse error: syntax error, unexpected $end in C:\Documents and Settings\My Documents\xampp\htdocs\index.php on line 42 the code I supplied shouldn't give one, I tested it. Oh I see, what was the other error? His IF statements are hard to read. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 They opened their function twice: function quadratic ($a, $b, $c, $root) { { Quote Link to comment Share on other sites More sharing options...
marcus Posted July 15, 2007 Share Posted July 15, 2007 They opened their function twice: function quadratic ($a, $b, $c, $root) { { That's what he was referring to in his first post. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 15, 2007 Share Posted July 15, 2007 First off I believe there are complex number handlers (they aren't classified as integers once becoming complexed) in php 5, however I'm not sure of the name. But even still if you want to deal with a complex number simply factor out sqrt(-1) and it becomes a non complex. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 15, 2007 Share Posted July 15, 2007 They opened their function twice: function quadratic ($a, $b, $c, $root) { { That's what he was referring to in his first post. Before the poster of this thread edited their post, they didn't show that they had already opened it on the next line. So really, infid3l unintentionally told them to add a second bracket. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.