Recap - Making Decisions
Coddy PHP 여정의 기초 섹션에 포함된 레슨 — 71개 중 33번째.
챌린지
쉬움입력에서 네 개의 값을 읽으세요: 정수 age, 문자열 membershipType, 문자열 promoCode, 그리고 정수 cartTotal.
학습한 의사결정 도구를 사용하여 적절한 출력을 결정하세요:
- Age Category (use if-elseif-else):
- age가 13보다 작으면
Child를 출력하세요 - 그렇지 않고 age가 20보다 작으면
Teen를 출력하세요 - 그렇지 않고 age가 65보다 작으면
Adult를 출력하세요 - 그렇지 않으면
Senior를 출력하세요
- age가 13보다 작으면
- Membership Discount (use switch): 새 줄에서 멤버십 유형에 따라 할인을 출력하세요:
gold→20% offsilver→10% offbronze→5% off- 기타 모든 값 →
No discount
- Promo Status (use null coalescing):
$appliedPromo변수를null로 설정하세요. null 병합 연산자를 사용하여$appliedPromo가 null이 아니면$displayPromo에$appliedPromo의 값을 할당하고, 그렇지 않으면 입력된promoCode를 사용하세요. 새 줄에서$displayPromo를 출력하세요. - Shipping (use ternary): 새 줄에서 삼항 연산자를 사용하여
cartTotal이 50 이상이면Free shipping을 출력하고, 그렇지 않으면Standard shipping을 출력하세요.
Example:
입력값이 25, gold, SAVE10, 75인 경우 출력은 다음과 같아야 합니다:
Adult
20% off
SAVE10
Free shipping입력값이 10, basic, WELCOME, 30인 경우 출력은 다음과 같아야 합니다:
Child
No discount
WELCOME
Standard shipping직접 해보기
<?php
// 입력 읽기
$age = intval(fgets(STDIN));
$membershipType = trim(fgets(STDIN));
$promoCode = trim(fgets(STDIN));
$cartTotal = intval(fgets(STDIN));
// TODO: 아래에 코드 작성
// 1. 연령 카테고리 (if-elseif-else 사용)
// 2. 멤버십 할인 (switch 사용)
// 3. 프로모 상태 (null 병합 사용)
$appliedPromo = null;
// 4. 배송 (삼항 연산자 사용)
?>기초의 모든 레슨
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