...

/

Solution: Calculate Compound Interest

Solution: Calculate Compound Interest

Look at the recursive solution to calculating compound interest.

We'll cover the following...

Solution

Press + to interact
# method definition with parameters
def compound_interest(principal_amount, rate, years)
# base case
if years == 0
return principal_amount
else
# calculation of compound interest using recursion
principal_amount = principal_amount + rate * principal_amount
compound_interest(principal_amount, rate, years - 1)
end
end

Explanation

Line 8: ...