Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Calculation for Masses of Gold are different between International standard and Myanmar, we need own calculator for that and that's the example
# Declaration
mass = [];
def check_num num
raise(ArgumentError, "Put Numbers only") if /[[:alpha:]]/.match(num)
# Enter mass
puts "enter kyat, pyel, ywey with coma seperated value. 'x,y,z' "
input = gets
check_num input
input.chomp.delete(' ').split(',').each do |m|
# In case of nil
mass[1] = mass[2] = 0 unless mass[1] and mass[2]
# defining range
raise(ArgumentError, "Pyel must lower than 16 and ywey must lower than 8 ") unless mass[1] < 16 and mass[2] < 8
puts "enter current Gold price"
input = gets
check_num input
price = input.to_f
puts "15 pyel or 16 pyel, enter numbers"
input = gets
check_num input
pyel = input.to_f
# Preparing Data
result = (mass[0] + (mass[1]+ mass[2]/8)/pyel) * price
puts result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.