Skip to content

Instantly share code, notes, and snippets.

@justuseapen
Last active December 29, 2015 00:39
Show Gist options
  • Save justuseapen/7587647 to your computer and use it in GitHub Desktop.
Save justuseapen/7587647 to your computer and use it in GitHub Desktop.
puts "How much $ is due?"
cost = gets.chomp.to_f
puts "How much has been tendered?"
tendered = gets.chomp.to_f
if tendered < cost
puts "The customer needs to pay you more dough, bro."
else
change = tendered - cost
change = change.to_f
end
DOLLAR = 1.00
QUARTER = 0.25
DIME = 0.10
NICKEL = 0.05
PENNY = 0.01
return_dollars = 0
return_quarters = 0
return_quarters
return_dimes = 0
return_nickels = 0
return_pennies = 0
if change > DOLLAR
return_dollars += 1 until return_dollars = change.floor
change = change - return_dollars
end
if change > QUARTER
return_quarters += 1 until change-(return_quarters*QUARTER) < QUARTER
change = change - (return_quarters*QUARTER)
end
if change > DIME
return_dimes += 1 until change-(return_dimes*DIME) < DIME
change = change - (return_dimes*DIME)
end
if change > NICKEL
return_nickels += 1 until change-(return_nickels*NICKEL) < NICKEL
change = change - (return_nickels*NICKEL)
end
if change > PENNY
return_pennies += 1 until change-(return_pennies*PENNY) < PENNY
change = change - (return_pennies*PENNY)
end
puts "Return to the customer:"
puts "#{return_dollars} dollars."
puts "#{return_quarters} quarters."
puts "#{return_dimes} dimes."
puts "#{return_nickels} nickels."
puts "#{return_pennies} pennies."
@HeroicEric
Copy link

Try to make sure that everything is indented consistently, with 2 spaces. It looks like you are using hard tabs. Make sure that you've got these settings in your Sublime Text settings https://gist.github.com/HeroicEric/77c860d2fe8d7ae0a98f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment