Reputation: 13
this is a simple calculation formula im doing trying ruby for the first time and stuck on a simple error bt need some guidance
#input
loan_amount = 0
rate = 0
period = 0
#output
monthly_payment = 0
print "Enter loan_amount: "
loan_amount = gets.to_f
print "Enter rate: "
rate = gets.to_f
print "Enter period: "
period = gets.to_f
monthly_payment = loan_amount((rate(1 + rate)**period)/(1 + rate)**period - 1)
puts "#{monthly_payment}"
Upvotes: -2
Views: 373
Reputation: 13428
There is a gem called Exonio: https://github.com/Noverde/exonio . This gem implements some of the Excel financials methods like: PMT, IPMT, PV, NPER...
Upvotes: 0
Reputation: 3869
Method gets
always return string
loan_amount = gets
=> "1"
You should transform strings to numbers before calculation:
loan_amount = gets
loan_amount = loan_amount.to_f
...
Upvotes: 1