-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRUBY.rb
More file actions
43 lines (35 loc) · 1.04 KB
/
RUBY.rb
File metadata and controls
43 lines (35 loc) · 1.04 KB
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
# weight multipliers
kgBase = 0.453592
lbsBase = 2.20462
# conversion type
print "What type of conversion do you need?\n - KG to LBS\n - LBS to KG\nSelect an option using numbers (1 or 2) : "
conversion = gets.chomp
# check conversion type
puts ""
if conversion == "1"
# get weight
print "Enter the amount of KG to convert : "
weight = gets.chomp.to_f()
# convert weight to lbs
convertedWeight = (((weight * lbsBase) * 10).round().to_f() / 10)
# print converted weight
print "#{weight} KG = #{convertedWeight} LBS"
elsif conversion == "2"
# get weight
print "Enter the amount of LBS to convert : "
weight = gets.chomp.to_f()
# convert weight to kg
convertedWeight = (((weight * kgBase) * 10).round().to_f() / 10)
# print converted weight
print "#{weight} LBS = #{convertedWeight} KG"
else
exit
end
# exit program
print "\n\nPress any key to exit . . ."
begin
system("stty raw -echo")
STDIN.getc
ensure
system("stty -raw echo")
end