/***************************************************
Compound Interest
Write a program that reads an annual interest rate
and a term (number of years) from the user, and
computes the ammount of money you'd have after that
number of years at that interest rate, assuming you
make $100.00 payments into the account at the
beginning of each year.
The formula for interest is this: If A is the
amount of money in your account at the beginning of
the year, and r is the annual interest rate, the
amount in your account at the end of the year is:
A*(1.0 + r/100.0)
***************************************************/
#include <iostream>
using namespace std;
main()
{
// Read interest rate
double r;
cout << "Enter interest rate: ";
cin >> r;
// Read number of years
int y;
cout << "Enter number of years: ";
cin >> y;
// INITIALIZATION FOR THE LOOP
double T;
T = 0.0; // We don't have any money yet
int i;
i = 0; // We haven't completed any iterations yet
// LOOP: COMPUTE y COMPOUNDING STEPS
while (i < y)
{
T = (T + 100.0)*(1.0 + r/100.0); // After year i + 1
i = i + 1; // record that we've completed an iteration
}
// Write out results
cout << "Final amount is: "
<< T << " dollars" << endl;
}