Created
December 14, 2012 03:06
-
-
Save JGallardo/4282377 to your computer and use it in GitHub Desktop.
Very basic script in Ruby to calculate mortgage payments.
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
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