Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Little Help with investment and interest rates (http://www.go4expert.com/forums/little-help-investment-rates-t18445/)

Prof. Krauf 9Jul2009 23:03

Little Help with investment and interest rates
 
Hi. I'm currently stuck here trying to figure out this code I'm trying to construct. I'm trying to write a function that computes future investment value at an interest rate given for a number of years.

so far I've constructed this.

Code:

#include <iostream>
using namespace std;
int main()
{
double futureInvestmentValue (double investmentAmount,
      double monthlyInterestRate, int years);

accumulatedValue =
investmentAmount x (1 + monthlyInterestRate)





system ("pause");
return 0;
}


I believe I should have something that involves/looks like this?

The amount invested: 1000
Annual interest rate: 9%

Years Future Value

1 1093.8
2 1196.41
...
29 13467.25
30 14730.57

xpi0t0s 10Jul2009 03:23

Re: Little Help with investment and interest rates
 
Start by working out how you would do it with a calculator. Then just convert that into C code.
If you can't do the second part, post how you would do it with a calculator and we can help you.

Prof. Krauf 10Jul2009 04:50

Re: Little Help with investment and interest rates
 
Do you mean something like using the InvestAmount as say 1000 and multiply that by 1 and 0.09. That would come out to be 1001.09 right? Errr.

Prof. Krauf 10Jul2009 07:07

Re: Little Help with investment and interest rates
 
hrm.

xpi0t0s 10Jul2009 11:30

Re: Little Help with investment and interest rates
 
How are you going to calculate the interest? Will it be once a year just adding 9% of the balance? Will it be monthly (as you seem to refer to this at some point) and if monthly will that be 1/12 of 9%, or the 12th root of (1+9%) (the latter allows for compound interest which will work out at 9%pa, whereas the former will give you more than 9% over the year)?

If it's just once a year adding 9% to the balance, then the calculation is just
balance = balance * (1+annualInterestRate)

so for example a balance of 1000 becomes 1000*(1+0.09) = 1090.

But where did you get the following figures from, and how was 1093.8 calculated?
Quote:

The amount invested: 1000
Annual interest rate: 9%

Years Future Value

1 1093.8
2 1196.41

Prof. Krauf 11Jul2009 02:42

Re: Little Help with investment and interest rates
 
Well I was just asking if it should look something like that.

what should go in for the cout part?

xpi0t0s 11Jul2009 04:35

Re: Little Help with investment and interest rates
 
Dunno. This is why I asked where you got those values from. 1093.8 obviously isn't 1000*(1+0.09) so that must have been derived by some other calculation.

Just trying an educated guess in a calculator: 1000*(1+0.09/12)^12=1093.806898 -- that seems close; that's the interest rate divided by 12 and applied monthly as compound, thus leading to 9.38% interest rather than the stated 9% -- that may or may not be correct, which is why you need to check where you got 1093.8 from -- who gave you that number, or was it a number you worked out yourself?

Why do you have a variable called monthlyInterestRate? If you're just calculating the value year on year at 9% per annum, you would use the annual rate directly. Or have you been told to calculate the value monthly?

> Well I was just asking if it should look something like that.

No, it'll be very different. You need to declare your variables, and you shouldn't be declaring futureInvestmentValue() as a private function.

> what should go in for the cout part?

Depends what you want to display. If you want to display
1 1093.8
2 1196.41
then probably what you want will be something like:
Code:

cout << yearNumber << " " << accumulatedValue << endl;
But you have quite a way to go before that.

Prof. Krauf 11Jul2009 06:58

Re: Little Help with investment and interest rates
 
this maybe?

Code:

#include <iostream>
using namespace std;

double futureInvestmentValue ( double investmentAmount,
                              double monthlyInterestRate,
                                int years);

int main()
{






  system ("pause");
  return 0;
}


double futureInvestmentValue ( double investmentAmount,
                              double monthlyInterestRate,
                                int years)
{

  // FV = PV ( 1 + i)

  //  investmentAmount * (1 + monthlyInterestRate);

 

}


xpi0t0s 11Jul2009 17:30

Re: Little Help with investment and interest rates
 
No idea. I'm stuck until you answer my questions.

Prof. Krauf 12Jul2009 05:01

Re: Little Help with investment and interest rates
 
I was given the number part from someone else, but I think I've got it. Annual result is what i need though adding in amounts from user.


All times are GMT +5.5. The time now is 09:49.