Created
April 18, 2014 18:48
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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