0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

今日は入力データを受け取る処理をしてみた!

image.png

今日の学び

繰り返し処理で番号をつける

  • each文の処理で値を1増やして更新する繰り返し処理で番号をつける
      • foods = ["パン","ラーメン",...]
      • index = 0
      • foods.each do |menu|
      • puts "#{index}. #{foods}"
      • index += 1
      • end

入力を受け取る

  • 変数 = gets.chompとすることで、エンターキーを押されるまでに入力された値を変数に代入することができる
    • puts "メニューを入力してください"
    • foods = gets.chomp
    • puts "#{foods}を注文します"
  • gets.chompで受け取った値は文字列になるため数値を入力する際はgets.chomp.to_iで数値に変換することで計算などに使える
    • puts "個数を入力してください"
    • number = gets.chomp.to_i
    • puts "#{number}個を注文します"
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?