Created
April 30, 2016 04:59
-
-
Save charmainetham/282379d11fe477dab5e1fe1a8526e779 to your computer and use it in GitHub Desktop.
pop bottles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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