Jump to content

[SOLVED] Error?!


sheep01

Recommended Posts

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

<?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

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

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

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

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

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.