This small application shows how to calculate the
compound interest of a saving.
Prerequisites:
When you deposit money in a savings account, your
money earns interest that is calculated every month or quarter, etc.
Because this is not money you need right away, the amount accrued can be
reinvested, thus boosting your interest so the next calculation would be
based on the original amount plus the new added value. This is the basis
of compound interest. The compound interest can be
calculated monthly or quarterly, etc based on the original amount you
deposited, the interest rate, and the period you and the institution agreed
upon. 
This application uses a dialog box equipped with the
necessary controls used to perform the type or related calculated. The
formula we will use to perform the calculations is as follows:

P = Principal 
r = Annual (Interest) Rate 
m = Number of Compounding Periods per Year 
n = Total Number of Compounding Periods 
A = Amount Earned After n periods 
Practical Learning: Starting the Exercise 

 Start Microsoft Visual C++ 2005
 Create a new CLR Windows Forms Application named CompoundInterest1
 Design the form as follows:

Control 
Name 
Text 
Additional Properties 
Form 

Compound Interest 
MaximizeBox: False 
GroupBox 

Preparation 

Label 

Principal: 

TextBox 
txtPrincipal 
0.00 
TextAlign: Right 
Label 

Interest Rate: 

TextBox 
txtInterestRate 
0.00 
TextAlign: Right 
Label 

% 

Label 

Number of Periods: 

TextBox 
txtPeriods 
1 
TextAlign: Right 
Label 

Years 

GroupBox 

Compound Frequency 

RadioButton 
rdoMonthly 
Monthly 
CheckAlign: MiddleRight 
RadioButton 
rdoQuarterly 
Quarterly 
CheckAlign: MiddleRight 
RadioButton 
rdoSemiannually 
Semiannually 
CheckAlign: MiddleRight 
RadioButton 
rdoAnnually 
Annually 
CheckAlign: MiddleRight 
Button 
btnCalculate 
Calculate 
On the form, set AcceptButton:
btnCalculate 
Button 
btnClose 
Close 
On the form, set
CancelButton: btnClose 
GroupBox 

Results 

Label 

Interest Earned: 
Align Text: Right 
TextBox 
txtInterestEarned 
0.00 
TextAlign: Right 
Label 

Amount Earned: 

TextBox 
txtAmountEarned 
0.00 
TextAlign: Right 

 On the form, doubleclick the Calculate button and implement its
OnClick() event as follows:
System::Void btnCalculate_Click(System::Object^ sender,
System::EventArgs^ e)
{
double Principal, AnnualRate, InterestEarned;
double FutureValue, RatePerPeriod;
int NumberOfPeriods, CompoundType;
Principal = double::Parse(txtPrincipal>Text);
AnnualRate = double::Parse(txtInterestRate>Text) / 100;
if( rdoMonthly>Checked )
CompoundType = 12;
else if( rdoQuarterly>Checked )
CompoundType = 4;
else if( rdoSemiannually>Checked )
CompoundType = 2;
else
CompoundType = 1;
NumberOfPeriods = int::Parse(txtPeriods>Text);
double i = AnnualRate / CompoundType;
int n = CompoundType * NumberOfPeriods;
RatePerPeriod = AnnualRate / NumberOfPeriods;
FutureValue = Principal * Math::Pow(1+i, n);
InterestEarned = FutureValue  Principal;
txtInterestEarned>Text = InterestEarned.ToString("C");
txtAmountEarned>Text = FutureValue.ToString("C");
}

 On the form, doubleclick the Close button and implement its OnClick()
event as follows:
System::Void btnClose_Click(System::Object^ sender,
System::EventArgs^ e)
{
Close();
}

 Test the application
 After using it, close it and return to your programming environment

