Created
December 13, 2023 21:51
-
-
Save yasalmasri/b92d6b9e2cdbd61483f0b82021567ed0 to your computer and use it in GitHub Desktop.
compound_interest.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'amazing_print' | |
def interest(amount:, rate:, months:, years:) | |
a = amount | |
1.upto(years) do | |
1.upto(months) do |month| | |
a += a * rate/months | |
a += amount | |
end | |
end | |
a.ceil(2) | |
end | |
ap interest(amount: 10000, rate: 0.12, months: 12, years: 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment