Skip to content

Commit

Permalink
Adding a explain compunding script.
Browse files Browse the repository at this point in the history
  • Loading branch information
algogrit committed Oct 12, 2019
1 parent fc9aad9 commit 7aa405e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions explain-compounding.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby

initial_amount = 100000
rate = 7
years = 10

puts "Use defaults - Amount: #{initial_amount}, Rate: #{rate}, Years: #{years}?"
default = gets

if default.include? "n"
puts "Enter amount: "
initial_amount = gets.to_i

puts "Enter rate of interest: "
rate = gets.to_i

puts "Enter total years: "
years = gets.to_i
end

amount = initial_amount

puts "You invested #{amount}"
years.times do |i|
amount = amount * ( 1 + (rate / 100.0) )
puts "At end of #{i+1} year: #{amount}"
end

puts "If you invest it for another #{years} years: #{amount * (( 1 + (rate / 100.0) ) ** years)}"

0 comments on commit 7aa405e

Please sign in to comment.