0

クレジットカード決済計算機を作ってみました。コード全体は次のとおりです。

m_counter = 0

def calc_payment
  payment_percentage = payment / balance * 100
  monthly_apr = apr / 12
  while balance > 0
   m_counter = m_counter + 1
   balance = balance / 100 * monthly_apr
   balance = balance - payment
  end
  puts
  puts "Monthly payment: $" + payment
  puts "Balance payoff: " + m_counter + " months" 
end

puts "Welcome to your credit card payment calculator!"
puts

puts "Please tell me your credit card balance."
balance = gets.chomp.to_f

puts "Please enter your interest rate %."
apr = gets.chomp.to_f

puts "How much $ would you like to pay every month?"
payment = gets.chomp.to_f

calc_payment

次のエラー メッセージが表示されます。

'calc_payment': main:Object の未定義のローカル変数またはメソッド 'payment' (NameError)

4

1 に答える 1