Compund Interest formula problem

Having trouble with the equation for compound interest.

the interest is supposed to be $43.34 according to the book, I am ending up with around $35

the actual equation is amount = principal * (1 + rate/t)^t where t = number of times compounded per year.

I still have to go through and clean up all the code I just want the formula working first.

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
33
34
35
36
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main ()
{
    float princ, rate, comp, savings, interest, rates, year; 
    
    
       
    cout<<"What is the principle amount? ";
    cin>>princ;
    cout<<"What is the interest rate? ";
    cin>>rate;
    cout<<"How many times is it compounded? ";
    cin>>comp;
    
    year = 12 / comp;
    rates = rate * .1;
    savings =  pow (princ * (1 + rates/comp),year);
    interest = savings - princ;
    
    cout<<"\n\nInterest Rate:        "<<rate;
    cout<<"\nTimes Compounded:     "<<comp;
    cout<<"\nPrincipal:           $"<<princ;
    cout<<"\nInterest:            $"<<interest;
    cout<<"\nAmount in Savings:   $"<<savings;
    
    
    
    
cin.get();
cin.get();
return 0;
}    
1
2
3
4
5
6
7
8
9
10
double principal = 1000.00 ;
double rate_of_interest_per_year = 0.10 ;
int number_of_years = 3 ;
int number_of_times_compounded_per_year = 4 ;

double rate_of_interest = rate_of_interest_per_year / number_of_times_compounded_per_year ;
int number_of_times_compounded = number_of_times_compounded_per_year * number_of_years ;

double amount = principal * std::pow( ( 1.0 + rate_of_interest ), number_of_times_compounded ) ;
double interest = amount - principal ;
Thanks for the code, was able to find the mistake in mine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cout << "What is the Principal: ";
cin >> principal;
cout << "What is the Interest Rate: ";
cin >> rate;
cout << "How many times Compounded: ";
cin >> t;



rates = rate/100; 

amount = principal * pow(1.0 + rates / t,t); 
interest = amount - principal;
Topic archived. No new replies allowed.