Loan Payment Calculator

Discussion in 'C#' started by jenl2881, Oct 17, 2011.

  1. jenl2881

    jenl2881 New Member

    Joined:
    Oct 17, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I need to make a Car Loan Payment calculator where the user enters the price of the car, the current interest rate, the number of months the vehicle will be financed for and clicks Calculate. I am assuming the user enters valid informatino

    Specifications:

    Code:
     ·         Code a private method named calculateTotalInterest that calculates the total interest paid on the car and returns it as a decimal value. Monthly interest is calculated as (Price * Interest Rate)  / 12. This method should accept the following arguments:
              Argument
             Description
                 price of car As Decimal
             The value entered for the Price of   Car
                 interest rate As Decimal
             The value entered for the Interest   Rate
                 number of months As Integer
             The value entered for the Number   of Months
                 monthly payment As Decimal
             The value calculated for Monthly   Payments:
       [CENTER][CENTER]Price   x (Interest Rate / 12)
      (1 – ( 1 + Interest Rate / 12 ) –Number   of Months)[/CENTER][/CENTER]
            ·         The results for Monthly Payment, Total Interest Paid, and Total Paid should be formatted as currency and displayed in the appropriate controls on the form
      
    
    When I try to run it (I am using Visual Studios) it hangs up at the payment calculation. Any help is GREATLY appreciated.
    
    
    This is what I have so far:
    
     using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
       
      namespace _549_LargeJ_Exam01
      {
          public partial class Form1 : Form
          {
              public Form1()
              {
                  InitializeComponent();
              }
       
              private void btnExit_Click(object sender, EventArgs e)
              {
                  this.Close();
              }
       
              private void btnCalculate_Click(object sender, EventArgs e)
              {
                  // declare variable
       
                  double months = Convert.ToDouble(txtMonths.Text);
                  double intrate = Convert.ToDouble(txtIntRate.Text);
                  double price = Convert.ToDouble(txtPrice.Text);
                  double payment = Convert.ToDouble(txtPayment.Text);
                  double intpaid = Convert.ToDouble(txtIntPaid.Text);
                  double totalpaid = Convert.ToDouble(txtTotalPaid.Text);
       
                  // conversion of text box values
       
                        
                  // Calculations
       
                  payment = (price * (intrate/12))/(1 - (Math.Pow((1+intrate/12), months)));
                  totalpaid = intpaid+(months*payment);
                  
       
                  intpaid = this.CalculateTotalInterest(price, intrate);
       
       
                  // display output
       
       
       
                  txtPayment.Text = payment.ToString("c");
                  txtIntPaid.Text = intpaid.ToString("c");
                  txtTotalPaid.Text = totalpaid.ToString("c");
       
              }
       
                  private double CalculateTotalInterest(double p, double i)
                  {
                      return (p * i)/12;
                  }
       
       
       
              
          }
      }
       
     
    Last edited by a moderator: Oct 17, 2011
  2. masterwarner

    masterwarner New Member

    Joined:
    Nov 7, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    So what problem are you exactly facing ?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice