forked from seanmsmith23/ruby-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroman.rb
49 lines (48 loc) · 904 Bytes
/
roman.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
puts "Give me a number between 0 and 3000!"
number = gets.chomp.to_i
loop {if number >= 1000
thousand = number / 1000
print "M"*thousand
number = number % 1000
elsif number >= 900
print "CM"
number = number - 900
elsif number >= 500
print "D"
number = number - 500
elsif number >= 400
print "CD"
number = number - 400
elsif number >= 100
hundred = number / 100
print "C" * hundred
number = number % 100
elsif number >= 90
print "XC"
number = number - 90
elsif number >= 50
print "L"
number = number - 50
elsif number >= 40
print "XL"
number = number - 40
elsif number >= 10
ten = number / 10
print "X" * ten
number = number % 10
elsif number >= 9
print "IX"
number = number - 9
elsif number >= 5
print "V"
number = number - 5
elsif number >= 4
print "IV"
number = number - 4
elsif number >= 1
print "I" * number
number = 0
else
break
end}
puts