Home

Math Functions: Making an Investment or Paying a Loan

     

Introduction

The Payment() function is used to calculate the regular payment of an investment. Its syntax is:

Extended __fastcall Payment(Extended Rate,
                            int NPeriods,
                            constExtended PresentValue,
                            const Extended FutureValue,
                            TPaymentTime PaymentTime);

In the following examples, a customer is applying for a car loan. The car costs $15500. It will be financed at 8.75% for 5 years. The dealer estimates that the car will have a value of $2500 when it is paid off. The dialog box is used to calculate the monthly payment (the Payments edit box) that the customer will make every month:

//---------------------------------------------------------------------------

#include <vcl.h>
#include <math.hpp>
#pragma hdrstop

#include "Exercise.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmExercise *frmExercise;
//---------------------------------------------------------------------------
__fastcall TfrmExercise::TfrmExercise(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmExercise::btnCalculateClick(TObject *Sender)
{
	Extended Present, Future, Rate, Payments, NPeriod;

	Present = StrToFloat(edtPresentValue->Text);
	Future = StrToFloat(edtFutureValue->Text);
	Rate = StrToFloat(edtInterestRate->Text);
	NPeriod = StrToFloat(edtPeriods->Text);

	// double Rate = TheRate;
	// Apply the function
	Payments = Payment(Rate / 100, NPeriod, -Present,
	Future, ptStartOfPeriod);
	// Display the payments
	edtMonthlyPayment->Text = FloatToStrF(Payments, ffCurrency, 8, 2);
}
//---------------------------------------------------------------------------
void __fastcall TfrmExercise::btnCloseClick(TObject *Sender)
{
	PostQuitMessage(0);
}
//---------------------------------------------------------------------------
Loan Payments
   

 

 
 
     
 

Home Copyright © 2010-2011 FunctionX, Inc.