Recap - Simple Calculations
CoddyのPHPジャーニー「基礎」セクションの一部 — レッスン 21/71。
チャレンジ
簡単入力から3つの数字を読み取ります: basePrice、taxPercent、および quantity。
以下のステップを実行して最終合計を計算します:
- 基本価格から始めます
- 基本価格を
(taxPercent / 100)で乗算して税を追加し、それを価格に加えます - 結果を数量で乗算します
- 合計から
15の固定割引を差し引きます - 最後に、
quantity ** 2で計算された送料を追加します
最終合計を出力します。
例:
入力が 50、10、および 2 の場合、出力は 99 であるべきです。理由は以下の通りです:
- 基本価格: 50
- 10%税を追加: 50 + (50 * 10 / 100) = 50 + 5 = 55
- 数量2で乗算: 55 * 2 = 110
- 割引15を差し引き: 110 - 15 = 95
- 送料を追加 (2 ** 2 = 4): 95 + 4 = 99
自分で試してみよう
<?php
// 入力の読み取り
$basePrice = intval(fgets(STDIN));
$taxPercent = intval(fgets(STDIN));
$quantity = intval(fgets(STDIN));
// TODO: 以下にコードを書く
// 1. 基本価格から始める
// 2. 税を追加 (basePrice * taxPercent / 100)
// 3. 数量で乗算
// 4. 15の割引を引く
// 5. 送料を追加 (quantity ** 2)
// 最終合計を出力
echo $finalTotal;
?>基礎のすべてのレッスン
4Comparison & Logical Operators
Comparison OperatorsEquality & IdentityLogical Operators Part 1Logical Operators Part 2Recap - Simple Logic2Variables and Data Types
NumbersStrings and QuotesBooleansNaming ConventionsRecap - Variable InitEmpty VariablesString ConcatenationGetting User InputCast to Different Types3Basic Operators
Arithmetic OperatorsModulo OperatorExponentiation OperatorCombined AssignmentIncrement/DecrementOperator PrecedenceRecap - Simple CalculationsString Operators