Skip to content

Instantly share code, notes, and snippets.

@designium
Forked from JGallardo/mortgageCalc.rb
Created July 18, 2019 16:37
Show Gist options
  • Save designium/0f3c7294240c56e2866b3ebe313eda34 to your computer and use it in GitHub Desktop.
Save designium/0f3c7294240c56e2866b3ebe313eda34 to your computer and use it in GitHub Desktop.
Very basic script in Ruby to calculate mortgage payments.
print "enter loan amount: "
loan = gets.chomp.to_i
print "Enter length of time in months: "
time = gets.chomp.to_i
print "Enter interest rate: "
rate = gets.chomp.to_f/100
i = (1+rate/12)**(12/12)-1
annuity = (1-(1/(1+i))**time)/i
payment = loan/annuity
puts "\n$%.2f per month" % [payment]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment