Skip to content

Instantly share code, notes, and snippets.

@rickhull
Forked from Dasms/test.rs
Last active November 9, 2017 01:21
Show Gist options
  • Save rickhull/0859a68ef88cdd100a4e4a9d6cb433d9 to your computer and use it in GitHub Desktop.
Save rickhull/0859a68ef88cdd100a4e4a9d6cb433d9 to your computer and use it in GitHub Desktop.
prices = {
"tennis ball" => 4.99,
"beach ball" => 12.99,
"giraffe" => 93.86,
}
print "What is your name? "
name = gets.chomp
puts "Alright #{name} what would you like to buy today?
We currently have #{prices.keys.join(', ')}."
prices.each { |name, price|
puts "The #{name} is #{price}"
}
balance = 120
puts "Your balance is #{balance}"
print "What would you like to purchase? >"
purchase = gets.chomp
if prices.key?(purchase)
price = prices[purchase]
balance -= price
puts "Congratulations, you bought a #{purchase} for #{price}"
puts "Your new balance is #{balance}"
else
puts "Sorry, we don't have #{purchase}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment