/**
 * Given the original price of a product and the discount percentage, calculate and return the discounted price.
 * If the discount is not within the range [0, 100], print an error message and ask the user to enter a valid discount.
 * If the user enters an invalid discount, continue asking for a valid discount until one is entered.
 *
 * @param originalPrice The original price of the product.
 * @param discount The discount percentage.
 * @return The discounted price of the product.
 */
fun calculateDiscountedPrice(originalPrice: Double, discount: Double): Double {

    var validDiscount = discount
    while (true) {
        if (validDiscount < 0 || validDiscount > 100) {
            println("Invalid discount! Please enter a value between 0 and 100.")
            // Ask user to enter a valid discount
            validDiscount = readLine()?.toDoubleOrNull() ?: continue
        } else {
            break
        }
    }
    
    val discountedPrice = originalPrice - (originalPrice * (validDiscount / 100))
    return discountedPrice
}
/**
 * Given the original price of a product and the discount percentage, calculate and return the discounted price.
 * If the discount is not within the range [0, 100], print an error message and ask the user to enter a valid discount.
 * If the user enters an invalid discount, continue asking for a valid discount until one is entered.
 *
 * @param originalPrice The original price of the product.
 * @param discount The discount percentage.
 * @return The discounted price of the product.
 */
fun calculateDiscountedPrice(originalPrice: Double, discount: Double): Double {
/**
 * Given the original price of a product and the discount percentage, calculate and return the discounted price.
 * If the discount is not within the range [0, 100], print an error message and ask the user to enter a valid discount.
 * If the user enters an invalid discount, continue asking for a valid discount until one is entered.
 *
 * @param originalPrice The original price of the product.
 * @param discount The discount percentage.
 * @return The discounted price of the product.
 */
fun calculateDiscountedPrice(originalPrice: Double, discount: Double): Double {

    var validDiscount = discount
    while (true) {
        if (validDiscount < 0 || validDiscount > 100) {
            println("Invalid discount! Please enter a value between 0 and 100.")
            // Ask user to enter a valid discount
            validDiscount = readLine()?.toDoubleOrNull() ?: continue
        } else {
            break
        }
    }
    
    val discountedPrice = originalPrice - (originalPrice * (validDiscount / 100))
    return discountedPrice
}