Menu
Coddy logo textTech

Calculating Tip And Total

Part of the Fundamentals section of Coddy's Kotlin journey. Lesson 43 of 93.

challenge icon

Challenge

Easy

In the previous lesson, you collected the bill amount, tip percentage, and number of people. Now, add the tip calculation logic to compute the tip amount and total bill.

Using the variables you already have, calculate:

  • tipAmount: the tip based on the bill amount and tip percentage
  • totalBill: the sum of the original bill and the tip amount

To calculate the tip amount, multiply the bill amount by the tip percentage divided by 100.

Update your output to display the tip amount and total bill instead of the raw inputs:

Welcome to Bill Split Calculator!
Tip amount: [tipAmount]
Total bill: [totalBill]

For example, if the inputs are 100.0, 20, and 4, the output should be:

Welcome to Bill Split Calculator!
Tip amount: 20.0
Total bill: 120.0

Input constraints: the bill and tip percentage are nonnegative, and the number of people is a positive integer. Numeric inputs are valid and finite.

Try it yourself

fun main() {
    // TODO: Write your code below to print the welcome message
    println("Welcome to Bill Split Calculator!")
    
    val billAmount = readLine()!!.toDouble()
    val tipPercentage = readLine()!!.toInt()
    val numberOfPeople = readLine()!!.toInt()
    
    println("Bill amount: $billAmount")
    println("Tip percentage: $tipPercentage")
    println("Number of people: $numberOfPeople")
}

All lessons in Fundamentals

Practice on your own: Kotlin playground