/**
 * This function calculates the total profit for a carpenter based on the number of hours worked and the hourly rate.
 * The carpenter charges a higher rate for overtime hours.
 *
 * @param hours Number of hours worked by the carpenter.
 * @param rate Hourly rate of the carpenter.
 * @return Total profit earned by the carpenter.
 */
fun calculateCarpenterProfit(hours: Int, rate: Double): Double {

    var overtimeHours = 0
    var regularHours = 0
    var totalProfit = 0.0

    var remainingHours = hours

    while (remainingHours > 0) {
        if (remainingHours > 40) {
            overtimeHours = 40
            remainingHours -= 40
            // Calculate overtime profit using the overtime rate
            val overtimeProfit = overtimeHours * rate * 1.5
            totalProfit += overtimeProfit
        } else {
            regularHours = remainingHours
            // Calculate regular profit using the regular rate
            val regularProfit = regularHours * rate
            totalProfit += regularProfit
            break
        }
    }

    return totalProfit
}
/**
 * This function calculates the total profit for a carpenter based on the number of hours worked and the hourly rate.
 * The carpenter charges a higher rate for overtime hours.
 *
 * @param hours Number of hours worked by the carpenter.
 * @param rate Hourly rate of the carpenter.
 * @return Total profit earned by the carpenter.
 */
fun calculateCarpenterProfit(hours: Int, rate: Double): Double {
/**
 * This function calculates the total profit for a carpenter based on the number of hours worked and the hourly rate.
 * The carpenter charges a higher rate for overtime hours.
 *
 * @param hours Number of hours worked by the carpenter.
 * @param rate Hourly rate of the carpenter.
 * @return Total profit earned by the carpenter.
 */
fun calculateCarpenterProfit(hours: Int, rate: Double): Double {

    var overtimeHours = 0
    var regularHours = 0
    var totalProfit = 0.0

    var remainingHours = hours

    while (remainingHours > 0) {
        if (remainingHours > 40) {
            overtimeHours = 40
            remainingHours -= 40
            // Calculate overtime profit using the overtime rate
            val overtimeProfit = overtimeHours * rate * 1.5
            totalProfit += overtimeProfit
        } else {
            regularHours = remainingHours
            // Calculate regular profit using the regular rate
            val regularProfit = regularHours * rate
            totalProfit += regularProfit
            break
        }
    }

    return totalProfit
}