Saladin Akara
Saladin Akara

Reputation: 2548

Calculating total return with compound interest

So, I'm trying to figure out the total amount of return from an investment of £5 with a daily interest rate of 1.01%. Obviously, I am wanting the compound interest rate, so I have this so far:

int main() {

    double i = 500;
    int loop;
    int loopa;
    double lowInterest;
    double highInterest;

    lowInterest = 1.01;
    highInterest = 1.75;

    cout.precision(2);

        for(loop = 1;loop < 1826;loop++) {
            if(i<1001) {
                i = i + ((i / 100) * lowInterest);
            }
            else {
                i = i + ((i / 100) * highInterest);
            }
        }

    cout << fixed << i << endl;

    return 0;

}

I am using 500 to represent the $5 just for personal preference. Am I doing this correctly? I get very strange results - 46592024576.00 for example - that make me think that somewhere I've made an error?

Any suggestions?

Upvotes: 1

Views: 1311

Answers (3)

Rufflewind
Rufflewind

Reputation: 8966

On a tangential note, your counter loop should start at 0 instead of 1, otherwise it will loop 1825 times instead of 1826.

Upvotes: 1

caf
caf

Reputation: 239171

The figure is about right - if you really were lucky enough to invest $5 at a daily interest rate of 1.01%, you'd end up with close to half a billion dollars after 5 years (a daily interest rate of 1.01% is an annual interest rate of ~ 3800%).

Are you sure you don't mean a daily interest rate of (1.01 / 365) % ?

Upvotes: 5

James Black
James Black

Reputation: 41858

I think you are doing manually what can be done with a simple equation.

http://qrc.depaul.edu/StudyGuide2009/Notes/Savings%20Accounts/Compound%20Interest.htm

A = P(1 + r/n) ^ nt

In this case

p = 5 (amount you invested)
r = 0.0101*365 (annual interest rate)
n = 365 (times compounded/yr)
t = 1  (number of years)

So, just implement the equation.

I may be off on the value of r as it has been years since I took Engineering Economics and I couldn't see how many years so I guessed one.

Upvotes: 3

Related Questions