請求額を分割する
CoddyのGDScriptジャーニー「基礎」セクションの一部。レッスン 41/92。
チャレンジ
簡単割り勘機能を追加しましょう。前の手順の内容はすべて残したまま、次のことを行います。
- 3つ目の入力として、請求額を分ける人数を読み取り、
int型に変換してnum_peopleに格納します。チップの割合を読み取った直後に読み取ってください。 total_amountをnum_peopleで割って、amount_per_personを計算します。total_amountを出力する行の後に、amount_per_personを出力します。
ラベルを付けず、数値だけを出力してください。たとえば、入力が64.3、9.0、2の場合、プログラムは次のように出力します。
Bill Split Calculator
70.087
35.0435自分で試してみよう
extends Node
func _ready():
print("Bill Split Calculator")
var bill_amount := float(OS.read_string_from_stdin())
var tip_percentage := float(OS.read_string_from_stdin())
var tip_amount := (tip_percentage / 100) * bill_amount
var total_amount := bill_amount + tip_amount
print(total_amount)
基礎のすべてのレッスン
自分で練習してみよう: GDScriptオンラインコンパイラ