LoginSignup
2
3

おみくじを改良しました

########################################
# おみくじプログラム           #########
########################################

#乱数を発生させる
num = rand(100)
flag1 = 0
while flag1 == 0 do
  # 0以下の整数と整数以外が入力されたら例外処理で再度整数入力を促す
  begin

    if num >= 0 then
      flag1 = 1
    else
      raise StandardError.new()
    end
  rescue => e
    e = "0以下の整数および整数以外は入力できません"
    puts e
  end
end
# 5で割る
ans = num % 5
# 5で割った余りでおみくじの結果を表示する。
if ans == 0
    puts("大吉")
elsif ans == 1
    puts("中吉")
elsif ans == 2
    puts("吉")
elsif ans == 3
    puts("小吉")
elsif ans == 4
    puts("凶")

end

2
3
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3