def get_input(question_to_ask)
puts question_to_ask
input = gets().chomp().to_f()
end
def get_price()
prices = []
price = get_input("Enter item price: ")
while (price != 0.0) do
prices.push(price)
price = get_input("Enter item price: ")
end
return prices
end
So...basically get_input is inside of get_price...so there's no need to
call it down later in the code? Right?
Then there's the second half of the code...
def get_subtotal(prices)
subtotal = 0.0
prices.each do |price|
subtotal = subtotal + price
end
return subtotal
end
def get_tax(tax)
return tax * SALES_TAX
end
get_price
get_subtotal
get_tax
puts "Subtotal: $" + subtotal.to_s()
puts "Sales Tax: $" + tax.to_s()
puts "Total: $" + total.to_s()
I get the same error (0 for 1) (Argument Error) for get_subtotal...
How do I get the array "prices" into the get_subtotal method?
How do I get the input from the get_prices method to be added together
in the get_subtotal method?
And then how do I get it to print each of those if the variables stay
inside the methods?
I've searched the internet and read the method chapters we're on in my
book and I can't find the answer...or an explanation that I can
understand...for some reason I just can't get this...
--
Posted via http://www.ruby-forum.com/.