Tin Roof Software interview question

Write a function to calculate compounding interest with the APR as a parameter

Interview Answers

Anonymous

3 Jan 2017

Not sure what "years = years + 1" is for in the answer above. It may even cause an infinite loop.

2

Anonymous

29 Feb 2020

using System; class Program { static void Main() { Console.WriteLine(CompoundInterest(1500, 0.043, 4, 6)); } /// /// CompoundInterest. /// static double CompoundInterest(double principal, double interestRate, int timesPerYear, double years) { // (1 + r/n) double body = 1 + (interestRate / timesPerYear); // nt double exponent = timesPerYear * years; // P(1 + r/n)^nt return principal * Math.Pow(body, exponent); } }

Anonymous

22 Jun 2016

def interest(principle, val, years): for x in range(0,years): principle = principle * (1+val) years = years + 1 return principle