/**
 * A veterinarian needs a function to calculate the dose of medication for animals based on their weight.
 * However, due to floating-point errors and the concept of epsilon, the function needs to handle these errors
 * and return the most accurate dose.
 *
 * Complete the code below to calculate the dose by using a for loop and considering floating-point error and epsilon.
 *
 * @param weight The weight of the animal in kilograms.
 * @param dosage The desired dosage in milligrams per kilogram.
 * @return The most accurate dose of medication to be administered to the animal.
 *
 * Note:
 * - The function should return 0.0 if either the weight or dosage is less than or equal to 0.
 * - The epsilon constant is set to 1e-9 for handling floating-point errors.
 */
fun calculateDose(weight: Double, dosage: Double): Double {

    val epsilon = 1e-9  // Floating-point error tolerance
    var dose = 0.0

    if (weight <= 0 || dosage <= 0) {
        return dose
    }

    for (i in 1..weight.toInt()) {
        val currentDose = i * dosage
        if (Math.abs(currentDose - weight * dosage) < epsilon) {
            dose = currentDose
        }
    }

    return dose
}
/**
 * A veterinarian needs a function to calculate the dose of medication for animals based on their weight.
 * However, due to floating-point errors and the concept of epsilon, the function needs to handle these errors
 * and return the most accurate dose.
 *
 * Complete the code below to calculate the dose by using a for loop and considering floating-point error and epsilon.
 *
 * @param weight The weight of the animal in kilograms.
 * @param dosage The desired dosage in milligrams per kilogram.
 * @return The most accurate dose of medication to be administered to the animal.
 *
 * Note:
 * - The function should return 0.0 if either the weight or dosage is less than or equal to 0.
 * - The epsilon constant is set to 1e-9 for handling floating-point errors.
 */
fun calculateDose(weight: Double, dosage: Double): Double {
/**
 * A veterinarian needs a function to calculate the dose of medication for animals based on their weight.
 * However, due to floating-point errors and the concept of epsilon, the function needs to handle these errors
 * and return the most accurate dose.
 *
 * Complete the code below to calculate the dose by using a for loop and considering floating-point error and epsilon.
 *
 * @param weight The weight of the animal in kilograms.
 * @param dosage The desired dosage in milligrams per kilogram.
 * @return The most accurate dose of medication to be administered to the animal.
 *
 * Note:
 * - The function should return 0.0 if either the weight or dosage is less than or equal to 0.
 * - The epsilon constant is set to 1e-9 for handling floating-point errors.
 */
fun calculateDose(weight: Double, dosage: Double): Double {

    val epsilon = 1e-9  // Floating-point error tolerance
    var dose = 0.0

    if (weight <= 0 || dosage <= 0) {
        return dose
    }

    for (i in 1..weight.toInt()) {
        val currentDose = i * dosage
        if (Math.abs(currentDose - weight * dosage) < epsilon) {
            dose = currentDose
        }
    }

    return dose
}