Skip to content

Instantly share code, notes, and snippets.

@zatherz
Created April 4, 2017 21:46
Show Gist options
  • Save zatherz/1f2f0565d94049474617eab5120fe30d to your computer and use it in GitHub Desktop.
Save zatherz/1f2f0565d94049474617eab5120fe30d to your computer and use it in GitHub Desktop.
printf "Enter two integer values:\n"
low_value = nil
high_value = nil
while !(!(low_value.nil?) && !(high_value.nil?))
printf "#DBG B: low_value=%s, high_value=%s\n", low_value.inspect, high_value.inspect
user_ans = STDIN.gets
if user_ans.nil?
STDERR.printf "\n <-- EOF! -->\n"
exit 1
end
user_ans = user_ans.strip
case user_ans
when /^\d+$/
if low_value.nil?
low_value = user_ans.to_i
else
high_value = user_ans.to_i
end
else
STDERR.printf "Invalid response: '%s'\n", user_ans
end
printf "#DBG E: low_value=%s, high_value=%s\n", low_value.inspect, high_value.inspect
end # until
exit 1 if low_value.nil?
exit 1 if high_value.nil?
if low_value > high_value
tmp = high_value
high_value = low_value
low_value = tmp
end
printf "%d\n", low_value
printf "%d\n", high_value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment