bank deposit program. Not returning correct values. Any suggestions?

I don't understand why my result is not the same as the one provided. I get 220 as my final balance. They get 128.2. I feel like my code is right...
The future value of a bank deposit is computed using the following:


Find the future value of a bank deposit

p principal, the amount deposited
r annual rate of interest
c number of times interest is compounded per year
n number of years
i interest rate per period

m total number of times interest is compounded
i = r / c
m = c * n
balance = p * ((1 + i))



Write a computer program using functions to:

a) Get p, r, c and n from the user
b) Calculate the value of i, m and balance
c) Display the results on the screen
d) Please make sure that you utilize the creation of your own class or class template in your code

Sample Output:

This program will calculate the future value of a bank deposit given the initial deposit, the annual interest rate, the number of times per year interest is compounded, and the number of years until maturity

Enter your initial deposit
100
Enter the annual interest rate
5
Enter the number of time interest is compounded per year
4
Enter the number of years before maturity
5
for an initial deposit of $100 at 5%
In 5 years you will have $128.204

Write your codes here:
Header:
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
#include <string>
using namespace std;
#ifndef moneyinfo_H
#define moneyinfo_H

class moneyinfo
{
public:
	moneyinfo();
	moneyinfo(int);
	float principaldeposited();
	float annualrateinterest();
	int timescompounded();
	int years();
	float interestperperiod();
	float totalnumberotimescompounded();
	float balance();
private:
float p;
float r;
int c;
int n;
float i;
int m;
float b;
};
#endif 

deffinitions:
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
37
38
39
40
41
42
43
#include "q1header.h"
#include <string>
#include <iostream>
using namespace std;

moneyinfo::moneyinfo(){
}
float moneyinfo::principaldeposited()
{
	cout<<"Enter your initial deposit"<<endl;
cin>> p;
return p;
}
float moneyinfo::annualrateinterest(){
	cout<<"Enter the annual interest rate"<< endl;
cin>>r;
return r;
}
int moneyinfo::timescompounded(){ 
cout<<"Enter the number of times interest is compounded per year"<< endl;
cin>>c;
return c;
}
int moneyinfo::years(){
	cout<<"Enter the number of years before maturity"<< endl;
cin>>n;
return n;
}
float moneyinfo::interestperperiod(){
	
i=r/c;
return i;
}
float moneyinfo::totalnumberotimescompounded(){
	
m=c*n;
return m;
}
float moneyinfo::balance(){
	
b=p*((1+i));
return b;
}

main code:
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
#include "q1header.h"
#include <iostream>
#include <string>
using namespace std;
float principaldeposited;
float annualrateinterest;
float balance;
int years;
int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

moneyinfo bankdeposit;
principaldeposited=bankdeposit.principaldeposited();
annualrateinterest=bankdeposit.annualrateinterest();
bankdeposit.timescompounded();
years=bankdeposit.years();
bankdeposit.interestperperiod();
bankdeposit.totalnumberotimescompounded();
balance=bankdeposit.balance();
cout<<"For an initial deposit of "<<principaldeposited<<" at "<<annualrateinterest<<"%."<<endl;
cout<<"In "<<years<< " years you will have "<<balance<<endl;
}
Anyone?
You need to divide the interest rate by 100.

e.g. 5% == 0.05

Also,
balance = p * ((1 + i))
gives the balance after one period only.

Try balance = p * ((1+i)^m)
Last edited on
Thanks, but how would I type the balance part in?
When I type the balance changes you made in above I get an error:

deffinitions q1.cpp(41): error C2296: '^' : illegal, left operand has type 'float'

I am sure this just means I have to change something, simple but I can't quite figure it out.
Nevermind. Used math.h with pow() and it is working now.
Topic archived. No new replies allowed.