Skip to content

Instantly share code, notes, and snippets.

@charmainetham
Created April 30, 2016 04:59
Show Gist options
  • Save charmainetham/282379d11fe477dab5e1fe1a8526e779 to your computer and use it in GitHub Desktop.
Save charmainetham/282379d11fe477dab5e1fe1a8526e779 to your computer and use it in GitHub Desktop.
pop bottles
# 2 empty empty bottles you get one free bottle
# for every 4 bottle caps you get one free bottle
# each bottle cost $2
def calculate(number)
empty_bottles(number) + bottle_caps(number)
end
def bottles_from_cash(cashtobottles)
@no_of_bottles = cashtobottles/2
end
def empty_bottles(a)
@no_of_bottles/2
end
def bottle_caps(b)
@no_of_bottles/4
end
def left_bot(c)
@no_of_bottles%2
end
def left_cap(d)
@no_of_bottles%4
end
loop do
puts "What amount do you want to spend? in dollars "
user_input = gets.chomp.to_i
if user_input == 0
puts "Invalid selection please put an actual amount"
break
else
puts "you will get #{bottles_from_cash(user_input)} bottles. You will get #{empty_bottles(user_input)} bottles from recyling empty bottles and #{bottle_caps(user_input)} bottles from recyling caps"
puts "you have #{left_bot(user_input)} of bottles and #{left_cap(user_input)} caps left. Buy more pop!!!!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment