-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed cafe bug #26
base: main
Are you sure you want to change the base?
fixed cafe bug #26
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# frozen_string_literal: true | ||
# require 'debug' | ||
|
||
DRINKS = [ | ||
{ name: 'コーヒー', price: '300' }, | ||
|
@@ -15,11 +16,12 @@ | |
].freeze | ||
|
||
def take_order(menus) | ||
# binding.break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上です。提出物からは消しましょう There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修正しました。 |
||
menus.each.with_index(1) do |menu, i| | ||
puts "(#{i})#{menu[:name]}: #{menu[:price]}円" | ||
end | ||
print '>' | ||
order_number = gets.to_i | ||
order_number = gets.to_i - 1 | ||
puts "#{menus[order_number][:name]}(#{menus[order_number][:price]}円)ですね。" | ||
order_number | ||
end | ||
|
@@ -30,5 +32,5 @@ def take_order(menus) | |
puts 'フードメニューはいかがですか?' | ||
order2 = take_order(FOODS) | ||
|
||
total = FOODS[order1][:price] + DRINKS[order2][:price] | ||
total = FOODS[order2][:price].to_i + DRINKS[order1][:price].to_i | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. これでOKです。しかし本質的にはorder1,2のようなわかりにくい命名が引き起こしがちな不具合ともいえます。したがってよりよい解答としては変数名の見直しまでするといいですね。修正は任意で結構です。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修正しました!今のコードはorder1はdrinkorderになって、食べ物の分はfoodorderになりました。 |
||
puts "お会計は#{total}円になります。ありがとうございました!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
提出物からはコメントアウトでなくて消しましょう