Reputation:
I am currently working on a small school project (Ruby) but I am getting this error (Wrong number of arguments (0 for 2)) that makes me wanna flip a table. :(
This is the code that I am trying to get to work:
puts "How much does the product cost?"
price = gets.to_f.round
puts "How much money will you give for it?"
money = gets.to_f
change = calculate_change(price, money)
I use that to get the user input, round the first to a fixnum and then the second one to a float. This is how my calculate_change method looks like:
def calculate_change(price, money)
return money - price
end
Upvotes: 0
Views: 4129
Reputation: 3816
Per @hirolau's comment, you need to make sure you declare calculate_change()
before the call to it.
def calculate_change(price, money)
money - price # return is optional in Ruby!
end
puts "How much does the product cost?"
price = gets.to_f.round
puts "How much money will you give for it?"
money = gets.to_f
change = calculate_change(price, money)
Upvotes: 2