diff --git a/2-variables/quadratic-formula/Quadratic.swift b/2-variables/quadratic-formula/Quadratic.swift index 0fb4379..78a33de 100644 --- a/2-variables/quadratic-formula/Quadratic.swift +++ b/2-variables/quadratic-formula/Quadratic.swift @@ -1,19 +1,14 @@ // Quadratic Formula 📈 -// Sonny Li +// Patrick Jakobsen -var a: Double = 6 -var b: Double = -7 -var c: Double = -3 +let a = 6.0 +let b = -7.0 +let c = -3.0 -var root1: Double -var root2: Double +let discriminant = (b * b - 4 * a * c).squareRoot() -// The positive root -root1 = (-b + (b*b - 4*a*c).squareRoot()) / (2*a) +let root1 = (-b + discriminant) / (2 * a) +let root2 = (-b - discriminant) / (2 * a) -// The negative root -root2 = (-b - (b*b - 4*a*c).squareRoot()) / (2*a) - -// Outputting the roots -print("Root 1 is \(root1)") -print("Root 2 is \(root2)") +print("Root 1:", root1) +print("Root 2:", root2)