Skip to content

Instantly share code, notes, and snippets.

@nainglinaung
Created April 18, 2014 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nainglinaung/11058822 to your computer and use it in GitHub Desktop.
Save nainglinaung/11058822 to your computer and use it in GitHub Desktop.
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)
end
# 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|
mass.push(m.to_f)
end
# 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