Question: everyone. I am trying to make a Quadratic Equation Solver but nothing is working. It is giving me the wrong answer. I get x = - 2.5 and x = - 3.5 when the answer is -2 and -1 for this equation:

x^2 + 3x + 2 

Here is my code:

```
<?php

$ax = $_REQUEST['num9'];

$bx = $_REQUEST['num10'];

$c = $_REQUEST['num11'];

$answerx1 = ($bx * -1) + (sqrt(($bx * $bx) + (-1 * 4 * $ax * $c)) / (2 * $ax));

$answerx2 = ($bx * -1) - (sqrt(($bx * $bx) + (-1 * 4 * $ax * $c)) / (2 * $ax));

echo "The answers are: x = " . $answerx1 . " or x = " . $answerx2;

?>

```

Answer: 
That's because you implemented the [formula](https://en.wikipedia.org/wiki/Quadratic_equation#Quadratic_formula_and_its_derivation) with errors.

This is the correct (and more readable) formula:

```
$answerx1 = (- $bx + sqrt($bx * $bx - 4 * $ax * $c)) / (2 * $ax);
$answerx2 = (- $bx - sqrt($bx * $bx - 4 * $ax * $c)) / (2 * $ax);

```
only formula is not the solution because sqrt($bx \* $bx - 4 \* $ax \* $c) can be complex and result will give you no solution.
To learn about complex numbers - [complex numbers](http://www.purplemath.com/modules/complex.htm)

in short complex number, "i" here is sqrt(-1)

To solve this you need to add condition :
eg: 3x2 + 4x + 2 = 0

```
$num = ($bx * $bx - 4 * $ax * $c)
if($num<0) {
 echo "(- $bx + ".sqrt(abs($bx * $bx - 4 * $ax * $c)."i)) / ".(2 * $ax);
 echo "\n";
 echo "(- $bx + ".sqrt(abs($bx * $bx - 4 * $ax * $c)."i)) / ".(2 * $ax);
} else {
  //(-b(+/-)sqrt(b*b-(4*a*c)))/2a formula method.
}

```

than you need to decide how you want to show your values of ax and bx. i have just echoed it as a string.