I tried to make a credit card payment calculator. Here's the whole code:
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
I'm getting an error message:
'calc_payment': undefined local variable or method 'payment' for main:Object (NameError)
(payment / balance) * 100or (better)100 * payment / balancerather thanpayment / balance * 100(clearer). Also, you could haveputs "hi\n\n"rather thanputs "hi"; puts; puts(stylistic difference only).