-
Notifications
You must be signed in to change notification settings - Fork 0
/
coins.rb
66 lines (55 loc) · 755 Bytes
/
coins.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require "pry"
puts "How much do you need change for?"
print "> "
@n = gets.to_i
@coins =[]
def change
until @n <= 0
@n -= 25
@coins << 25
end
if @n < 0
@n += 25
@coins.delete_at(@coins.count - 1)
elsif @n == 0
total
end
until @n <= 0
@n -= 10
@coins << 10
end
if @n < 0
@n += 10
@coins.delete_at(@coins.count - 1)
else
total
end
until @n <= 0
@n -= 5
@coins << 5
end
if @n < 0
@n += 5
@coins.delete_at(@coins.count - 1)
else
total
end
until @n <= 0
@n -= 1
@coins << 1
end
if @n < 0
@n += 1
@coins.delete_at(@coins.count - 1)
else
total
end
end
def total
@coins.each do |c|
print "#{c} "
end
@coins=[]
puts ""
end
change