Skip to content

Instantly share code, notes, and snippets.

@ebba0194
Created December 9, 2017 04:58
Show Gist options
  • Save ebba0194/58db72daa65ad03f23e09fcd82258784 to your computer and use it in GitHub Desktop.
Save ebba0194/58db72daa65ad03f23e09fcd82258784 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
double calcInt (double, double, double, double&);
int main(){
double deposit, ratePer, rateDec, endAmount, years, endBalance;
cout<<"Enter initial deposit: $";
cin>>deposit;
cout<<"Enter interest rate (%): ";
cin>>ratePer;
rateDec = ratePer/100;
cout<<"Enter desired end amount: ";
cin>>endAmount;
endBalance = calcInt (deposit, rateDec, endAmount, years);
cout<<"\nIt will take "<<years<<" years."
<<"\nEnding balance = "<<endBalance;
return (0);
}
double calcInt (double deposit, double rateDec, double endAmount, double& years){
double temp=deposit;
double endBalance;
int n = 0;
do{
endBalance = temp+(temp*rateDec);
temp = endBalance;
n++;
}while (temp <= endAmount);
years = n;
return (endBalance);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment