Math Functions: The Periodic Payments of a Loan

 Introduction
 While the InterestPayment() function calculates the amount paid as interest for a loan, the PeriodPayment() function calculates the actual amount that applies to the balance of the loan. This is referred to as the principal. Its syntax is:
```Extended __fastcall PeriodPayment(const Extended Rate,
int Period,
int NPeriods,
const Extended PresentValue,
const Extended FutureValue,
TPaymentTime PaymentTime);```

Here is an example:

```//---------------------------------------------------------------------------

#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, PPayment;
int Periods, NPeriod;

Present = StrToFloat(edtPresentValue->Text);
Future = StrToFloat(edtFutureValue->Text);
Rate = StrToFloat(edtInterestRate->Text) / 12;
Periods = StrToInt(edtPeriods->Text);
NPeriod = StrToInt(edtNPeriods->Text);

// Apply the function
PPayment = PeriodPayment(Rate / 100, Periods, NPeriod,
-Present,
Future,
ptStartOfPeriod);
// Display the payment
edtPeriodicPayment->Text = FloatToStrF(labs(PPayment), ffCurrency, 8, 2);
}
//---------------------------------------------------------------------------
void __fastcall TfrmExercise::btnCloseClick(TObject *Sender)
{
PostQuitMessage(0);
}
//---------------------------------------------------------------------------```