2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

おみくじを改良しました

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

#乱数を発生させる
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
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?