
//*****************************************************************************
////  Course:             COMS 2203 Foundations of Computer Programming II
////  Semester:           Fall 2004
////  Assignment Number:  #1                             
////  Author Name:        DarC KonQuesT                        
////  Date Written:       August 20, 2004
////                                                         
////  Description of Program:                              
////  Program calculates the balance of a savings account, taking into account    
////  principle amount, interest, compound interest, and length of time                             
////*****************************************************************************
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void balance(double princ, float inte, double comp, double yr, double& total)
{
 total = princ * pow((1 + (inte / comp)), (comp * yr));
}


int main()
{
  double  principle, total, years, compound;
  float interest;
  cout << fixed << showpoint;
  cout << "This program calculates the balance of a savings account." << endl << endl;
  cout << "P:  Principal amount" << endl << "I:  Annual interest rate(e.g., 5.0%)" << endl << "Q:  Number of times that interest to be compounded per year" << endl << "N:  Number of years that the money is to be kept in the account" << endl << endl;
  cout << "Please enter the values for P, I, Q, and N..." << endl << endl;
  cout << "P = ";
  cin >> principle;
  cout << endl << "I = ";
  cin >> interest;
  interest = interest / 100;
  cout << endl << "Q = ";
  cin >> compound;
  cout << endl << "N = ";
  cin >> years;

   cout << endl << endl << "Year     Balance" << endl << "---------------" << endl;
    
     for(int x = 1; x <= years; x++)
     {
         balance(principle, interest, compound, x, total);
         cout << setprecision(0) << x << "    " << setprecision(2) << total << endl;
     }
    
  cout << endl << "------------------" << endl;
return 0;
}


