Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

How do i add the values of keys together within one hash?

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' def initialize(checkings, balance) @Checkings = checkings @balance = balance

end

def snack(food) total_items = {} @val = total_items.values puts "How much is #{food} " price = gets.chomp.to_i total_items[food] = price loop do puts "Wanna buy more food?(Yes/No)" answer = gets.chomp case answer when "Yes", "yes", "YES" puts "What other snack you wanna buy?" snack = gets.chomp puts "Im sorry i can't see the lable how much is that?" price = gets.chomp total_items[snack] = price.to_i when "No", "no", "NO" puts "These are the items you are buying." p "----------------------------------------------------" total_items.each_key {|key| puts "You bought #{key}"} p "----------------------------------------------------" puts "Averaging total #{total_items.values}" total_items.values.to_s total_items.each do |par| par.collect { |l| l + @val } break end end end end

end

ally_bank = Bank.new("Chase", 120)
ally_bank.snack("Chips")
"""""""""""""""""""""""""""""""""'''''''''''''''''''''''''''''''''''''''''''''''''''''''

the probel begins on line each mether for total_items.

Alex Hinson
Alex Hinson
20,184 Points

Do you think you could format the question with markdown to make it easier to read whats going on? That'll probably get some more people willing to respond. Check out the "Markdown Cheatsheet" for info on how to do that.

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

Alot of people have been telling me this but idk how to format it =( like wheres the mark down cheat sheet?