Skip to content

Instantly share code, notes, and snippets.

@cdesch
Last active April 16, 2016 21:46
Show Gist options
  • Save cdesch/8e711b734afe188dd261e3312c96f405 to your computer and use it in GitHub Desktop.
Save cdesch/8e711b734afe188dd261e3312c96f405 to your computer and use it in GitHub Desktop.
#Calc Change
#April 16 2016
puts "Hi this is my change calculator" #\n
print "Enter your bill: " # 21.32 # 21.353
#bill = gets
#bill = bill.chomp
#bill = bill.to_f
#bill = bill.round(2)
bill = gets.chomp.to_f.round(2)
print "Enter in the amount you will pay the bill with: " #22.00
paid_amount = gets.chomp.to_f.round(2)
puts "your bill is #{bill}"
puts "your paid amount is #{paid_amount}"
change = 0
if bill > paid_amount
puts "pay more money you cheapskate"
else
amount = (bill - paid_amount).abs
puts "your change will be #{amount.round(2)}"
#amount = 3.21
#amount = amount * 100
amount *= 100
amount = amount.to_i
#break it down into 20 dollar
count = amount / 2000
amount -= 2000 * count
puts "#{count} 20 dollar bills"
#break it down into 10 dollar
count = amount / 1000
amount -= 1000 * count
puts "#{count} 10 dollar bills"
#break it down into 5 dollar
count = amount / 500
amount -= 500 * count
puts "#{count} 5 dollar bills"
#break it down into 1 dollar
count = amount / 100
amount -= 100 * count
puts "#{count} 1 dollar bills"
#break it down into quarters
count = amount / 25
#amount = amount - 25 * count
amount -= 25 * count
#puts count.to_s + " quarters"
puts "#{count} quarters"
# dimes
count = amount / 10
amount -= 10 * count
puts "#{count} dimes"
# nickles
count = amount / 5
amount -= 5 * count
puts "#{count} nickles"
# pennies
puts "#{amount} pennies"
end
#Calc Change
#April 16 2016
puts "Hi this is my change calculator" #\n
print "Enter your bill: " # 21.32 # 21.353
#bill = gets
#bill = bill.chomp
#bill = bill.to_f
#bill = bill.round(2)
bill = gets.chomp.to_f.round(2)
print "Enter in the amount you will pay the bill with: " #22.00
paid_amount = gets.chomp.to_f.round(2)
puts "your bill is #{bill}"
puts "your paid amount is #{paid_amount}"
change = 0
if bill > paid_amount
puts "pay more money you cheapskate"
else
amount = (bill - paid_amount).abs
puts "your change will be #{amount.round(2)}"
#amount = 3.21
#amount = amount * 100
amount *= 100
amount = amount.to_i
#break it down into 20 dollar
count = amount / 2000
amount -= 2000 * count
puts "#{count} 20 dollar bills"
#break it down into 10 dollar
count = amount / 1000
amount -= 1000 * count
puts "#{count} 10 dollar bills"
#break it down into 5 dollar
count = amount / 500
amount -= 500 * count
puts "#{count} 5 dollar bills"
#break it down into 1 dollar
count = amount / 100
amount -= 100 * count
puts "#{count} 1 dollar bills"
#break it down into quarters
count = amount / 25
#amount = amount - 25 * count
amount -= 25 * count
#puts count.to_s + " quarters"
puts "#{count} quarters"
# dimes
count = amount / 10
amount -= 10 * count
puts "#{count} dimes"
# nickles
count = amount / 5
amount -= 5 * count
puts "#{count} nickles"
# pennies
puts "#{amount} pennies"
end
#Calc Change 2
#April 16 2016
def change(amount, value, name)
count = amount / value
#puts "#{count} #{name}" if count != 0
#if count != 0
#puts "#{count} #{name}"
#end
#unless count == 0
#puts "#{count} #{name}"
#end
puts "#{count} #{name}" unless count == 0
amount -= value * count
end
puts "Hi this is my change calculator" #\n
print "Enter your bill: " # 21.32 # 21.353
bill = gets.chomp.to_f.round(2)
print "Enter in the amount you will pay the bill with: " #22.00
paid_amount = gets.chomp.to_f.round(2)
puts "your bill is #{bill}"
puts "your paid amount is #{paid_amount}"
if bill > paid_amount
puts "pay more money you cheapskate"
else
amount = (bill - paid_amount).abs
puts "your change will be #{amount.round(2)}"
#change the amount to an integer
amount *= 100
amount = amount.to_i
{Twenties: 2000, Tens: 1000, Fives: 500, Ones: 100, Quarters: 25, Dimes: 10, Nickles: 5, Pennies: 1}.each do |money, value|
amount = change(amount, value, money.to_s)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment