Skip to content

Instantly share code, notes, and snippets.

@pr4v33n
Created March 6, 2011 16:40
Show Gist options
  • Save pr4v33n/857388 to your computer and use it in GitHub Desktop.
Save pr4v33n/857388 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
using namespace std;
void foo(int, int, double, double);
double calculate_CI(int, int, double, double);
int main()
{
int years, timesCompounded; //The number of years deposited, the number of times per year compounded
double interestRate, principal; //The nominal annual interest rate, the amount of money deposited.
years = 10;
timesCompounded = 4;
interestRate=5;
principal = 100;
foo(years, timesCompounded, interestRate, principal);
years = 20;
timesCompounded = 12;
interestRate=5;
principal = 100;
foo(years, timesCompounded, interestRate, principal);
years = 50;
timesCompounded = 365;
interestRate=5;
principal = 100;
foo(years, timesCompounded, interestRate, principal);
system ("pause"); /* Only on MS Windows */
return 0;
}
double calculate_CI(int y, int t, double i, double p) {
return (p * pow(1+i/(100*t), t*y));
}
void foo(int y, int t, double i, double p) {
cout<<"If you deposit "<<p<<" at "<<i<<" nominal annual interest rate ";
cout<<"compounded "<<t<<" times per year for " <<y<<" years,\n";
cout<<"you will have "<< fixed << setprecision(2) << calculate_CI(y,t,i,p) <<" in your account.\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment