Conversation
JunichiIto
reviewed
Feb 6, 2024
cafe.rb
Outdated
| order_number = gets.to_i | ||
| order_number = gets.to_i - 1 | ||
| until order_number.between?(0, menus.size - 1) | ||
| print "番号は選択肢の中から入力してください\n>" |
There was a problem hiding this comment.
要件としては表示されている番号をすべて選択可能にする、だけで十分です。
番号の再入力は要件にないのでカットしちゃってください〜。
Owner
Author
There was a problem hiding this comment.
コメントありがとうございます。失礼いたしました!
まずはちゃんと用件通り、シンプルに実装することを心がけます!
cafe.rb
Outdated
| 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.
そもそもの問題として、価格が文字列になっていて何か嬉しいことがあるのか?から考えてみてください。
あと、変数が連番だとうっかりミスをおこしやすいので、良い変数も検討してみてください。
Owner
Author
There was a problem hiding this comment.
ありがとうございます。
そもそもの問題として、価格が文字列になっていて何か嬉しいことがあるのか?から考えてみてください。
実装した時はここの計算処理以外でpriceは文字列で表示していたので、計算処理の箇所だけto_iするほうが妥当だろうと考えたのですが、そもそも以下のように文字列に埋め込んで表示していたのでpriceを数値にしても何も問題がないことに気づきました。。修正いたします。
#{menus[order_number][:price]}
また、変数名についてもありがとうございます。処理が動いたことで修正完了としてしまっていました!
シンプルにfood_order、drink_orderが分かりやすいかと思いましたので、合わせて修正いたします。
Owner
Author
|
@JunichiIto
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
プラクティス カレンダーのプログラム(Ruby) | FBCを実装。
対応
必要修正要件
例: (1)コーヒー と (2)アップルパイを頼むと、お会計が意図した金額にならない。
追加対応
実装詳細
頼んだつもりのメニューが選択できない。
最後の番号のメニューを選択するとエラーとなる。
-1になってしまい、最後の配列の値を選択できてしまうため選択肢の範囲以外の入力がされた場合、再入力を促す処理を念の為追加お会計額が異様に高い。
違う番号のドリンク、フードを注文したとき、お会計が正しくない。
Screenshot
実行結果