title: Quadratic Formula in Swift
body: <p>I tried creating an x value calculator for the quadratic formula. </p>
  
  <p>Code:</p>
  
  <pre><code>var firstXValueVAR = 1.0
  var secondXValueVAR = 1.0
  var squaredValueVAR = 1.0
  var firstOperationValueVAR = "+"
  var secondOperationValueVAR = "+"
  var constantValueVAR = 0.0
  
  var topFormula = 0.0
   var topFormula2 = 0.0
  var bottomFormula = 0.0
  
  var TotalSquaredValue = 0
  
  var bSquared = 0
  
  var totalX = 0.0
  var totalX2 = 0.0
  </code></pre>
  
  <p>Next, when I click "Go" to calculate X, I have this, and I'm not really sure what I did wrong, but every time I print X, it says nan, and it also says that for topFormula and topFormula2 (= nan).</p>
  
  <pre><code>func updateValues(){
      var secondXValueInt = Int(secondXValueVAR)
      var firstXValueInt = Int(firstXValueVAR)
      var squaredValueInt = Int(squaredValueVAR)
      var constantValueInt = Int(constantValueVAR)
      bSquared = secondXValueInt &lt;&lt; 2
      TotalSquaredValue = firstXValueInt &lt;&lt; squaredValueInt
      firstXValueVAR = Double(firstXValue.text!)!
      secondXValueVAR = Double(secondXValue.text!)!
      squaredValueVAR = Double(squaredValue.text!)!
      constantValueVAR = Double(constantValue.text!)!
      if operations.contains(firstOperationValue.text!){
          firstOperationValueVAR = firstOperationValue.text!
          if secondOperationValueVAR == "*"{
              topFormula = -(secondXValueVAR) + sqrt(Double(bSquared) - (4 * firstXValueVAR * constantValueVAR))
              bottomFormula = 2 * firstXValueVAR
              totalX = topFormula / bottomFormula
  
              print(squaredValue)
  
  
              topFormula2 = -(secondXValueVAR) - sqrt(Double(bSquared) - (4 * firstXValueVAR * constantValueVAR))
              bottomFormula = 2 * firstXValueVAR
              totalX2 = topFormula2 / bottomFormula
  
              print(topFormula)
              print(topFormula2)
              print(bottomFormula)
  
              print("X = \(totalX) &amp; \(totalX2)")
          }
          if secondOperationValueVAR == "/"{
              topFormula = -(secondXValueVAR) + sqrt(Double(bSquared) - (4 * firstXValueVAR * constantValueVAR))
              bottomFormula = 2 * firstXValueVAR
              totalX = topFormula / bottomFormula
  
                print(squaredValue)
  
              topFormula2 = -(secondXValueVAR) - sqrt(Double(bSquared) - (4 * firstXValueVAR * constantValueVAR))
              bottomFormula = 2 * firstXValueVAR
              totalX2 = topFormula2 / bottomFormula
  
              print(topFormula)
              print(topFormula2)
              print(bottomFormula)
  
              print("X = \(totalX) &amp; \(totalX2)")
          }
          if secondOperationValueVAR == "+"{
              topFormula = -(secondXValueVAR) + sqrt(Double(bSquared) - (4 * firstXValueVAR * constantValueVAR))
              bottomFormula = 2 * firstXValueVAR
              totalX = topFormula / bottomFormula
  
                print(squaredValue)
  
              topFormula2 = -(secondXValueVAR) - sqrt(Double(bSquared) - (4 * firstXValueVAR * constantValueVAR))
              bottomFormula = 2 * firstXValueVAR
              totalX2 = topFormula2 / bottomFormula
  
              print(topFormula)
              print(topFormula2)
              print(bottomFormula)
  
              print("X = \(totalX) &amp; \(totalX2)")
          }
          if secondOperationValueVAR == "-"{
              topFormula = -(secondXValueVAR) + sqrt(Double(bSquared) - (4 * firstXValueVAR * constantValueVAR))
              bottomFormula = 2 * firstXValueVAR
              totalX = topFormula / bottomFormula
  
                print(squaredValue)
  
              topFormula2 = -(secondXValueVAR) - sqrt(Double(bSquared) - (4 * firstXValueVAR * constantValueVAR))
              bottomFormula = 2 * firstXValueVAR
              totalX2 = topFormula2 / bottomFormula
  
              print(topFormula)
              print(topFormula2)
              print(bottomFormula)
  
              print("X = \(totalX) &amp; \(totalX2)")
          }
  
      }
      if operations.contains(secondOperationValue.text!){
          secondOperationValueVAR = secondOperationValue.text!
      }
  
  
  
  }
  @IBAction func GoAction(sender: AnyObject) {
      updateValues()
  }
  </code></pre>