-
-
Save pr4v33n/857388 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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