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
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
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
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
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
Share on other sites

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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.