Menu
Coddy logo textTech

Splitting The Bill

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

challenge icon

Challenge

Easy

In the previous lesson, you calculated the tip amount and total bill. Now, add the final calculation to split the total bill among all the people.

Using the variables you already have, calculate:

  • amountPerPerson: the total bill divided by the number of people

Update your output to display only the amount each person should pay:

Welcome to Bill Split Calculator!
Each person pays: [amountPerPerson]

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

Welcome to Bill Split Calculator!
Each person pays: 30.0

The calculation works as follows: tip is 20.0, total bill is 120.0, and divided by 4 people equals 30.0 per person.

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()
    
    val tipAmount = billAmount * tipPercentage / 100
    val totalBill = billAmount + tipAmount
    
    println("Tip amount: $tipAmount")
    println("Total bill: $totalBill")
}

All lessons in Fundamentals

Practice on your own: Kotlin playground