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 5 years have passed since last update.

ペアプロ お買い物プログラム2 回答

Last updated at Posted at 2019-10-30
order.rb
#注文
def order(num, menus, total_price)
  puts "いくつ注文しますか?"
  quantity = gets.to_i
  menu = menus[num]
  price = menu * quantity
  total_price += price
  puts "他にご注文はございますか?"
  return total_price
end

#レジ
def register(total_price)
  puts "お会計は#{total_price}になります"
  puts "ありがとうございました!"
  exit
end

#メニュー
burger = 500
potato = 300
drink = 150
menus = [burger, potato, drink]
total_price = 0
puts "いらっしゃいませ、ご注文をどうぞ"

while true do
  puts "[0]:ハンバーガー・500円"
  puts "[1]:ポテト・300円"
  puts "[2]:ドリンク・150円"
  puts "[3]:お会計へ"
  num = gets.to_i
  if num == 3
    register(total_price) #レジへ
  else
    total_price = order(num, menus, total_price) #注文へ
  end

end

補足:イートインかテイクアウトかで税率を変える機能をつけても楽しいかも

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?