「Computer Science Programming Basics in Ruby」やその他の情報源を使用して Ruby を独学しようとしています。質問に行き詰まっていますが、この本には解決策がありません。
課題は、2D グラフ上の 2 つの点を指定すると、線 (水平または垂直) またはその勾配 (正または負) を説明するメッセージを出力するプログラムを作成することです。これは私がこれまでに持っているものです。
# Get the first point from a user
puts "Please enter Point A's X value."
x_1 = gets.to_i
puts "Please enter Point A's Y value."
y_1 = gets.to_i
# Get the second point from a user
puts "Please enter Point B's X value."
x_2 = gets.to_i
puts "Please enter Point B's Y value."
y_2 = gets.to_i
slope = ((y_1-y_2) / (x_1-x_2))
#Check to see if the line is vertical or horizontal and the slope is +ve or -ve
case
when (slope == 0) then
puts "The line is horizontal."
when (slope > 0) then
puts "The slope is positive."
when (slope < 0) then
puts "The slope is negative."
when (x_1-x_2 == 0) then
puts "The line is vertical."
end
puts "The line is vertical!"
ZeroDivisionError を取得せずにゼロリターンで割った値を作成するにはどうすればよいですか?