Lesson goal: Using the Quadratic Formula

Previous: Throwing darts to find Pi | Home | Next: The Pythagorean Theorem Calculator

Remember solving quadractic equations? If you have a quadractic equation in "standard form," which is $Ax^2+Bx+C=0$, then the two solutions to this equation will be $$x=\frac{-B\pm\sqrt{B^2-4AC}}{2A}.$$

In grade-school algebra the equations are kept simple in that the roots (or answers) to quadractic equations are always real. If you look carefully at the quadractic formula, there is a $\sqrt{B^2-4AC}$. As you know, you cannot take the square root of a negative number (if you want roots that are real numbers). In other words, $B^2-4AC$ (which is called the discriminant) must always be $\ge 0$, so in a quadratic equation solver, we must check that this is true (with an if statement) before continuing.

Now you try. Put some inequality to test in the if statement. You also have to complete the x1= and x2= lines to give the $+$ and $-$ roots, as computed with the quadratic formula above.

Type your code here:

See your results here: