/**
 * Calculate the total discount applied to a given price.
 * The discount can be in percentage (%) or fixed amount ($).
 *
 * @param price The original price of an item.
 * @param discount The discount to be applied, either in percentage (%) or fixed amount ($).
 * @return The total discount applied to the price.
 */
fun calculateTotalDiscount(price: Double, discount: String): Double {

    var totalDiscount = 0.0

    // If the discount is given in percentage
    if (discount.last() == '%') {
        val discountPercent = discount.substring(0, discount.length - 1).toDouble()
        if (discountPercent > 50) {
            totalDiscount = price * 0.5 // Apply maximum discount of 50%
        } else {
            totalDiscount = price * (discountPercent / 100)
        }
    }

    // If the discount is given in fixed amount
    else if (discount.first() == '$') {
        val discountAmount = discount.substring(1).toDouble()
        if (discountAmount > price) {
            totalDiscount = price // Apply maximum discount equal to price
        } else {
            totalDiscount = discountAmount
        }
    }

    return totalDiscount
}
/**
 * Calculate the total discount applied to a given price.
 * The discount can be in percentage (%) or fixed amount ($).
 *
 * @param price The original price of an item.
 * @param discount The discount to be applied, either in percentage (%) or fixed amount ($).
 * @return The total discount applied to the price.
 */
fun calculateTotalDiscount(price: Double, discount: String): Double {
/**
 * Calculate the total discount applied to a given price.
 * The discount can be in percentage (%) or fixed amount ($).
 *
 * @param price The original price of an item.
 * @param discount The discount to be applied, either in percentage (%) or fixed amount ($).
 * @return The total discount applied to the price.
 */
fun calculateTotalDiscount(price: Double, discount: String): Double {

    var totalDiscount = 0.0

    // If the discount is given in percentage
    if (discount.last() == '%') {
        val discountPercent = discount.substring(0, discount.length - 1).toDouble()
        if (discountPercent > 50) {
            totalDiscount = price * 0.5 // Apply maximum discount of 50%
        } else {
            totalDiscount = price * (discountPercent / 100)
        }
    }

    // If the discount is given in fixed amount
    else if (discount.first() == '$') {
        val discountAmount = discount.substring(1).toDouble()
        if (discountAmount > price) {
            totalDiscount = price // Apply maximum discount equal to price
        } else {
            totalDiscount = discountAmount
        }
    }

    return totalDiscount
}