I am working on a program to calculate the interest of a CD. The program will compile however, I can't get the correct answer. I believe the problem is in the final formula.
#include<iostream>
#include<cmath>
usingnamespace std;
int main()
{
double principle; //intial investment
double interestRate; //interest rate
int months; CD Term
double FormulaInterest=interestRate/100+1; //Convert Interest so it can be
//calculated.
cout<<"Please enter the principle amount."<<endl; //intial investment from user.
cin>>principle;
cout<<endl;
cout<<"Please enter the interest rate."<<endl; //interest rate from user.
cin>>interestRate;
cout<<endl;
cout<<"How many months is this CD?"<<endl; //CD term from user.
cin>>months;
cout<<endl;
double final=principle*pow(FormulaInterest,months); //Formula to determine total
// a*b^c.
cout<<"Your CD will total $"<<final<<endl;
return main();
}
line 10 - change months to double from int as there'll be some divisions involved; and comment out CD term
line 26 - pow(FormulaInterest, months) does this:
(1 + interestRate/100)^(months), so you need to annualize the months variable
line 31 - return 0, not return main()