Compounding Interest Program

Good morning.

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
#include<cmath>

using namespace 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();
}


Any advice?
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()
Topic archived. No new replies allowed.