Created
September 18, 2014 03:38
-
-
Save deedeelavinder/37ff12fcbc8717d1eb6b to your computer and use it in GitHub Desktop.
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
class ChangeMachineInstructions | |
def intitialize(user_amount) | |
@user_amount = user_amount | |
@dollars | |
@quarters | |
@dimes | |
@nickels | |
@pennies | |
end | |
def offer_service | |
puts "Enter your money in the $0.00 format and watch the magic happen." | |
@user_amount = gets.chomp.to_f*100 | |
make_change | |
end | |
def make_change | |
@dollars = @user_amount.to_i/ 100 | |
@quarters = (@user_amount.to_i % 100) / 25 | |
@dimes = ((@user_amount.to_i % 100) % 25) / 10 | |
@nickels = (((@user_amount.to_i % 100) % 25) % 10) / 5 | |
@pennies = ((((@user_amount.to_i % 100) % 25) % 10) % 5) | |
puts "" | |
show_results | |
continue | |
end | |
def show_results | |
puts "You have #{@dollars} dollar bill/s, #{@quarters} quarter/s, #{@dimes} dime/s, #{@nickels} nickel/s and #{@pennies} penny/ies." | |
puts "" | |
end | |
def continue | |
puts "If you'd like to do that again, just type 'yes' \n" "" "Otherwise, just hit 'enter'." | |
continue_now = gets.chomp.downcase | |
if continue_now == "yes" | |
offer_service | |
elsif | |
puts "See you next time!" | |
exit | |
end | |
end | |
end | |
change_machine = ChangeMachineInstructions.new | |
change_machine.offer_service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment