Loan Calculator development

I am developing a loan calculator that is going to display the results on form 2 in formatted currency and formatted percent. If all the requirements are met, how do I get the calculate button to show form 2? Also, I am getting a fatal error that says unexpectedly found nil while unwrapping.

 

Here is my code.

 

            dblCost = Double(txtVehicleCost.text!)!

            dblDownPayment = Double(txtDownPayment.text!)!

            intMonths = Int(txtNumberOfMonths.text!)!

            dblAPR = Double(txtAPR.text!)!

            dblTax = Double(txtTax.text!)!

         

            dblTax = dblTax / 100

            dblTotalTax = dblCost * dblTax

            dblLoan = (dblCost + dblTotalTax) – dblDownPayment

            dblMonthlyRate = dblAPR / 100 / dblMONTHS_YEAR

            dblMonthlyPayment = dblLoan * (dblMonthlyRate / (1 – pow(1 + dblMonthlyRate, Double(-intMonths))))

            dblTotalInterest = dblMonthlyPayment * Double(intMonths) – dblLoan

            dblTotalAmount = dblMonthlyPayment * Double(intMonths) + dblDownPayment

        

          

            lblMessage.text = “”

         

          

            let fVehicleCost = NSNumber(value: dblCost)

            let fResultCost = NumberFormatter.localizedString(from: fVehicleCost, number: .currency)

            lblVehicleCost.text! = String(fResultCost)

         

          

            let fDownPayment = NSNumber(value: dblDownPayment)

            let fResultDownPayment = NumberFormatter.localizedString(from: fDownPayment, number: .currency)

            lblDownPayment.text = String(fResultDownPayment)

         

          

            lblNumberOfMonths.text = “(intMonths)”

         

          

            let fAPR = NSNumber(value: dblAPR)

            let fResultAPR = NumberFormatter.localizedString(from: fAPR, number: .percent)

            lblAPR.text = String(fResultAPR)

         

          

            let fTax = NSNumber(value: dblTax)

            let fResultTax = NumberFormatter.localizedString(from: fTax, number: .percent)

            lblTax.text = String(fResultTax)

 

          

            let monthlyPayment = NSNumber(value: dblMonthlyPayment)

            let resultMonthlyPayment = NumberFormatter.localizedString(from: monthlyPayment, number: .currency)

            lblMonthlyPayment.text = String(resultMonthlyPayment)

         

          

            let totalInterest = NSNumber(value: dblTotalInterest)

            let resultTotalInterest = NumberFormatter.localizedString(from: totalInterest, number: .currency)

            lblTotalInterest.text = String(resultTotalInterest)

         

          

            let totalTax = NSNumber(value: dblTotalTax)

            let resultTotalTax = NumberFormatter.localizedString(from: totalTax, number: .currency)

            lblTotalTax.text = String(resultTotalTax)

         

          

            let totalAmount = NSNumber(value: dblTotalAmount)

            let resultTotalAmount = NumberFormatter.localizedString(from: totalAmount, number: .currency)

            lblTotalAmount.text = String(resultTotalAmount)

Powered by WPeMatico

About

You may also like...

Comments are closed.