/**
 * This exercise is designed to test your understanding of floating-point numbers and modifying elements using slicing.
 *
 * Write a function called 'calculateBmi' that takes two arguments: weight (in kilograms) and height (in meters).
 *
 * The function should calculate the Body Mass Index (BMI) using the formula:
 * BMI = weight / (height * height)
 *
 * However, the BMI value should be rounded to 2 decimal places.
 *
 * Once you have the BMI value, convert it to a string, and return it sliced in the following format:
 * 'BMI: XX.XX'
 *
 * For example, if weight = 75 and height = 1.75, the function should return 'BMI: 24.49'.
 *
 * Remember to handle potential division by zero errors by checking if the height is zero.
 * If the height is zero, return 'Invalid height!'.
 */
fun calculateBmi(weight: Double, height: Double): String {

    if (height == 0.0) {
        return "Invalid height!"
    }

    val bmi = (weight / (height * height)).toDouble().format(2)
    return "BMI: ${bmi}"
}

fun Double.format(digits: Int) = "%.${digits}f".format(this)
/**
 * This exercise is designed to test your understanding of floating-point numbers and modifying elements using slicing.
 *
 * Write a function called 'calculateBmi' that takes two arguments: weight (in kilograms) and height (in meters).
 *
 * The function should calculate the Body Mass Index (BMI) using the formula:
 * BMI = weight / (height * height)
 *
 * However, the BMI value should be rounded to 2 decimal places.
 *
 * Once you have the BMI value, convert it to a string, and return it sliced in the following format:
 * 'BMI: XX.XX'
 *
 * For example, if weight = 75 and height = 1.75, the function should return 'BMI: 24.49'.
 *
 * Remember to handle potential division by zero errors by checking if the height is zero.
 * If the height is zero, return 'Invalid height!'.
 */
fun calculateBmi(weight: Double, height: Double): String {
/**
 * This exercise is designed to test your understanding of floating-point numbers and modifying elements using slicing.
 *
 * Write a function called 'calculateBmi' that takes two arguments: weight (in kilograms) and height (in meters).
 *
 * The function should calculate the Body Mass Index (BMI) using the formula:
 * BMI = weight / (height * height)
 *
 * However, the BMI value should be rounded to 2 decimal places.
 *
 * Once you have the BMI value, convert it to a string, and return it sliced in the following format:
 * 'BMI: XX.XX'
 *
 * For example, if weight = 75 and height = 1.75, the function should return 'BMI: 24.49'.
 *
 * Remember to handle potential division by zero errors by checking if the height is zero.
 * If the height is zero, return 'Invalid height!'.
 */
fun calculateBmi(weight: Double, height: Double): String {

    if (height == 0.0) {
        return "Invalid height!"
    }

    val bmi = (weight / (height * height)).toDouble().format(2)
    return "BMI: ${bmi}"
}

fun Double.format(digits: Int) = "%.${digits}f".format(this)