How to Make a Bank with Interest- Difficulty 🟧 or 6.5/10

Interesting idea! You could also use compound interest formulas (a = p(1+r/n)^(n*t) when a is the updated value, p is the initial value, r is the interest rate (1% = 0.01), n is the number of times the interest is compounded in a given time period (usually a year, but can be changed to suit your scenario), and t is the number of time periods (years) in a given scenario) to allow for more complex calculations.

For example, $2500 being deposited in the bank for 300 seconds (compounded every minute) with an interest rate of 5% would be represented as a = 2500((1+0.05/1)^(1*5)) and would be returned as $3,190.70 once removed from the bank. Alternatively, if you don’t want to find a predetermined amount of time to reference (like 60 seconds) and round down to find that value (note that rounding down works because the 5 in my equation would become 0 and anything to the power of 0 is 1 - this ensures that you don’t accidentally multiply the starting value by 0 and lose all your money), you could use continually compounding interest to constantly update that value: a = p*(2.7183^(r*t))

Input the starting value as p, the interest rate as r, and the number of seconds as t. Our previous example would be represented as a = 2500*(2.7183^(0.05*5)), which would return a value of $3,210.06 - note that you still have to round down to find the nearest minute value (because the original equation uses t to represent years and we’re just changing it to minutes for convenience), but the outputted value is a larger number. Continuous compounding is considered to be the most favorable type of interest compounding because the interest is reinvested into the account more frequently than any other method, so if you want to maximize the amount of money that a user is getting out of the bank at any given time, you might want to consider using that method instead.

Feel free to ask if you have any questions… that was a pretty vague explanation :]

20 Likes