Page 1 of 3

Hey you programming nerds

Posted: Sun Oct 24, 2010 11:21 am
by Erico
I have to make a program in c++ where the user inputs money he has in the bank, then how many years he chooses and the interest he gets, The interest is compounded annually - so each time through a loop is another year and the interest is calculated and added to the principle for that year. what would the formula I would put in the loop be?

Posted: Sun Oct 24, 2010 11:26 am
by Hypnos
Lol, I remember doing the exact thing in my programming class. Been so long since I have used any of it, no way I could do it now :P

Posted: Sun Oct 24, 2010 12:26 pm
by Moonde
Wouldn't it be something like this?

princ = princ + (princ * interest / 100);

Posted: Sun Oct 24, 2010 1:48 pm
by Erico
That doesn't add onto the previous years, im usually good at this but im juggling three projects right now and just cant wrap my head around the mathematical equation.

the interest for the next year has to account for the interest that was already added on from the previous year, for instance.

100$ to start, with 10% interest would come out to 110$ after the first year, i then need it to continue to add interest onto that for however many years the user puts in. so the second year should be 110$ * 10% = 111$ and so on and so on.

I just can't think of how to actually write that as a formula

Posted: Sun Oct 24, 2010 1:48 pm
by godpigeon
simply loop it how ever many years.

that's the quick and dirty answer at least.

Posted: Sun Oct 24, 2010 2:02 pm
by ascanius
future value=principal(1+rate)^years

That's not programming, it's math.

Posted: Sun Oct 24, 2010 2:28 pm
by godpigeon
And how do you get algorithms in programing?... It's math

Posted: Sun Oct 24, 2010 3:54 pm
by Erico
ascanius wrote:future value=principal(1+rate)^years

That's not programming, it's math.
I need to figure out how to make that work in the program

That's not math, it's programming lolz :)

Posted: Sun Oct 24, 2010 3:57 pm
by ascanius
godpigeon wrote:And how do you get algorithms in programing?... It's math
Just because something is an algorithm doesn't make it math. Writing something that has a machine make a tone at a certain time is an algorithm, but I wouldn't call it math. It's just an instance of human logic being translated into mathematical logic, with the intended resolution's nature hardly being described as mathematical.

Interest compounding, on the hand, is an event that is both delineated and elucidated by mathematics. In this case, math is the intended function, and not just an intangible means to an end. Compounding is just a word used to describe variable rate exponential change, be it interest gains or inflation losses.

I wasn't trying to slight your response, just point out that he asked programmers for a math question.

Posted: Sun Oct 24, 2010 4:00 pm
by Atelo
I got the impression he was looking for the line of C++ code that would calculate it, not just the math formula.