这是一个简单的计算公式,即时通讯做尝试首次红宝石和停留在一个简单的错误BT需要一些指导“+”串不能强迫Fixnum对象(类型错误)
#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
错误时我计算式I最终得到此[主未定义的方法率:对象(NoMethodError)]
monthly_payment = loan_amount((rate(1 + rate)**period)/(1 + rate)**period - 1)
puts "#{monthly_payment}"
你必须先将字符串转换为数字,例如''12'.to_f'。 'period','loan_amount'和'roi'是转换的候选对象。 – sschmeck
你的问题是什么? – sawa