Menu
Coddy logo textTech

팁과 총액 계산하기

Coddy Swift 여정의 기초 섹션에 포함된 레슨 — 86개 중 39번째.

challenge icon

챌린지

쉬움

이전 레슨에서는 사용자로부터 총 청구 금액, 팁 백분율, 인원수를 입력받았습니다. 이제 팁 금액과 팁을 포함한 총 청구 금액을 계산하는 로직을 추가하세요.

이미 가지고 있는 값들을 사용하여 다음을 계산하세요:

  1. 팁 금액(tip amount): 총 청구 금액에 팁 백분율을 곱한 후 100으로 나눈 값
  2. 팁 포함 총액(total with tip): 총 청구 금액에 팁 금액을 더한 값

계산을 수행하기 전에 팁 백분율을 Int에서 Double로 변환해야 함을 기억하세요.

출력이 정확히 다음 형식을 따르도록 업데이트하세요:

Welcome to the Bill Split Calculator!
Bill: [billTotal]
Tip: [tipPercentage]%
People: [numberOfPeople]
Tip amount: [tipAmount]
Total with tip: [totalWithTip]

예를 들어, 입력값이 100.0, 20, 4인 경우 출력은 다음과 같아야 합니다:

Welcome to the Bill Split Calculator!
Bill: 100.0
Tip: 20%
People: 4
Tip amount: 20.0
Total with tip: 120.0

직접 해보기

print("Welcome to the Bill Split Calculator!")

if let billInput = readLine(), let billTotal = Double(billInput) {
    if let tipInput = readLine(), let tipPercentage = Int(tipInput) {
        if let peopleInput = readLine(), let numberOfPeople = Int(peopleInput) {
            print("Bill: \(billTotal)")
            print("Tip: \(tipPercentage)%")
            print("People: \(numberOfPeople)")
        }
    }
}

기초의 모든 레슨