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 ?> ??? Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/ Share on other sites More sharing options...
infid3l Posted July 15, 2007 Share Posted July 15, 2007 function quadratic ($a, $b, $c, $root) { Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298586 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... Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298590 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? Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298591 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 Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298592 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 ?> Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298593 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 ?> Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298594 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 ?> Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298595 Share on other sites More sharing options...
infid3l Posted July 15, 2007 Share Posted July 15, 2007 I just posted that two replies up... Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298596 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. Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298597 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. Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298599 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) { { Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298600 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. Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298601 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. Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298602 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. Link to comment https://forums.phpfreaks.com/topic/60032-solved-error/#findComment-298604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.