Skip to content

Instantly share code, notes, and snippets.

@JGallardo
Created December 14, 2012 03:06
Show Gist options
  • Save JGallardo/4282377 to your computer and use it in GitHub Desktop.
Save JGallardo/4282377 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