Recap - Simple Calculations
Parte de la sección Fundamentos del Journey de PHP de Coddy — lección 21 de 71.
Desafío
FácilLee tres números de la entrada: basePrice, taxPercent y quantity.
Calcula el total final realizando los siguientes pasos:
- Comienza con el precio base
- Agrega el impuesto multiplicando el precio base por
(taxPercent / 100)y sumándolo al precio - Multiplica el resultado por la cantidad
- Resta un descuento fijo de
15del total - Finalmente, agrega una tarifa de envío calculada como
quantity ** 2
Imprime el total final.
Ejemplo:
Si las entradas son 50, 10 y 2, la salida debería ser 99 porque:
- Precio base: 50
- Agregar impuesto del 10%: 50 + (50 * 10 / 100) = 50 + 5 = 55
- Multiplicar por cantidad 2: 55 * 2 = 110
- Restar descuento 15: 110 - 15 = 95
- Agregar envío (2 ** 2 = 4): 95 + 4 = 99
Pruébalo tú mismo
<?php
// Leer entrada
$basePrice = intval(fgets(STDIN));
$taxPercent = intval(fgets(STDIN));
$quantity = intval(fgets(STDIN));
// TODO: Escribe tu código a continuación
// 1. Comenzar con el precio base
// 2. Agregar el impuesto (basePrice * taxPercent / 100)
// 3. Multiplicar por cantidad
// 4. Restar descuento de 15
// 5. Agregar tarifa de envío (quantity ** 2)
// Salida del total final
echo $finalTotal;
?>Todas las lecciones de Fundamentos
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 Types5Conditional Logic
If StatementIf - ElseThe Ternary OperatorNull Coalescing OperatorSwitch StatementRecap - Making Decisions3Basic Operators
Arithmetic OperatorsModulo OperatorExponentiation OperatorCombined AssignmentIncrement/DecrementOperator PrecedenceRecap - Simple CalculationsString Operators