这是我试图计算利息的代码
def coumpoundinterest
print "Enter the current balance: "
current_balance = gets
print "Enter the interest rate: "
interest_rate = gets
_year = 2012
i = 0
while i < 5 do
current_balance = current_balance + current_balance * interest_rate
puts "The balance in year " + (_year + i).to_s + " is $" + current_balance.to_s
i = i + 1
end
end
这是我遇到所有麻烦的地方
current_balance = current_balance + current_balance * interest_rate
如果我保持代码原样,我会收到一个错误,即无法将字符串强制输入 FixNum。如果我在 interest_rate 之后添加 .to_i,那么我会将该行乘以数次。我如何处理红宝石中的算术?