Menu
Coddy logo textTech

Getting Input

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

challenge icon

Challenge

Easy

In the previous lesson, you printed a welcome message. Now, extend your program to collect the bill information from the user.

After the welcome message, read three inputs and store them in variables:

  • First input: the bill amount (read as a string, convert to Double)
  • Second input: the tip percentage (read as a string, convert to Int)
  • Third input: the number of people splitting the bill (read as a string, convert to Int)

After reading the inputs, print them in the following format:

Welcome to Bill Split Calculator!
Bill amount: [billAmount]
Tip percentage: [tipPercentage]
Number of people: [numberOfPeople]

For example, if the inputs are 85.50, 15, and 3, the output should be:

Welcome to Bill Split Calculator!
Bill amount: 85.5
Tip percentage: 15
Number of people: 3

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!")
}

All lessons in Fundamentals

Practice on your own: Kotlin playground