# Ruby Tutorial – Learn how to Program – Weight Conversion

Write a program that converts kilogram to pounds, ounces, grams, and US tons.

Output:

This program converts kilogram to pounds, ounces, grams, and US tons.
Enter the weight(kilogram/s): 5

********************
5.0 kilogram/s is equivalent to :
11.0231 pound/s
176.36984999999999 ounce/s
5000.0 gram/s
0.0055000000000000005 US ton/s

.

Solution:

length = 0
print “This program converts kilogram to pounds, ounces, grams, and US tons.”
print “Enter the weight(kilogram/s): ”
length = Float(gets.chomp)
print “\n********************\n”
print length, ” kilogram/s is equivalent to :\n”
print length * 1.30488, ” pound/s\n”
print length * 60975.60976, ” ounce/s\n”
print length * 999210.97561, ” gram/s\n”
print length * 35.28683, ” US ton/s\n”

This is a free programming tutorial for you.

Check out more Ruby tutorials on this site.

here’s my github repository for the Rubycodes of this blog:

MoreCodes – Ruby

Feel free to leave some comments. Thank you

—-

—-

# Share the post

Ruby Tutorial – Learn how to Program – Weight Conversion

×