# Something's wrong

Hey, I already tried learning Swift with Swift Playgrounds on Mac, though I thought trying here.
I got a little problem in the Quadratic Equation project.
It was pretty easy and I didn’t have any problems to type all the code but when testing with provided numbers, I don’t get what’s supposed to output for root2, always the good number, but when it’s supposed to be positive number it’s negative and the same backwards. Maybe I’m bad with maths?? idk but still, here’s my code.

``````var a : Double = 3.0
var b : Double = -11.0
var c : Double = -4.0

var root1 : Double
var root2 : Double

//Première solution
root1 = b*b - 4*a*c

root1 = root1.squareRoot()
root1 += -b
root1 /= 2*a

//Seconde solution
root2 = b*b - 4*a*c

root2 = root2.squareRoot()
root2 -= -b
root2 /= 2*a
print("La première solution est \(root1) et la deuxième solution est \(root2).")
``````

Here for exemple it will output

``````root1 = 4
root2 = 0.3333333333
``````

but it says that’s supposed to output

``````root1 = 4
root2: -0.3333333333
``````

I checked ten times and I still don’t get what’s wrong…

Hello!
It’s this line that’s letting you down;

``````root2 -= -b
``````

which is doing;
root2 = root2 - (-b)
and works out as;
(2 = 13 - 11)

whereas what the equation wants is;
root2 = -b - root2
which is;
(-2 = 11 - 13)

Hope that helps

2 Likes