Created
January 3, 2016 21:37
-
-
Save mPanasiewicz/9388c941bedd3ac53ec2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
puts "Please enter cost" | |
cost = gets.chomp.to_f | |
puts "Please enter money" | |
money = gets.chomp.to_f | |
rest = money - cost | |
while rest < 0 | |
puts "You still owe %.2f" % rest | |
tw,te,f,o,q,d,n,p = 0,0,0,0,0,0,0,0 | |
dollars = (money- cost) | |
change = (money - cost - dollar)*100 | |
if dollars >= 20 | |
tw = dollars/20 | |
dollars = dollars % 20 | |
elsif dollars >= 10 | |
te = dollars/10 | |
dollars = dollars % 10 | |
elsif dollars >= 5 | |
f = dollars/5 | |
dollars = dollars % 5 | |
elsif dollars >= 1 | |
o = dollars | |
elsif change >= 25 | |
q = change/25 | |
change = change % 25 | |
elsif change >= 10 | |
d = change/10 | |
change = change % 10 | |
elsif change >= 5 | |
n = change/5 | |
change = change % 5 | |
elsif change >= 1 | |
p = change | |
end | |
final = (money - (cost+tw+te+f+o+q+d+n+p)) | |
print ("your change is $%.2f: \n | |
%.0f twenties \n | |
%.0f tens \n | |
%.0f fives \n | |
%.0f ones \n | |
%.0f quarters \n | |
%.0f dimes \n | |
%.0f nickels \n | |
%.0f pennies" % final) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment