/**
 * A function to calculate the average speed of an aircraft.
 *
 * @param distance The distance covered by the aircraft (in kilometers).
 * @param time The total time taken by the aircraft (in hours).
 * @return The average speed of the aircraft (in kilometers per hour).
 */
fun calculateAverageSpeed(distance: Double, time: Double): Double {

    if (distance <= 0 || time <= 0) {
        return 0.0
    }

    var totalDistance = 0.0
    var totalTime = 0.0
    var counter = 0

    while (true) {
        print("Enter the distance covered during the interval (in kilometers): ")
        val currentDistance = readLine()!!.toDouble()
        if (currentDistance == 0.0) {
            break
        }

        print("Enter the time taken for the interval (in hours): ")
        val currentTime = readLine()!!.toDouble()
        if (currentTime == 0.0) {
            break
        }

        totalDistance += currentDistance
        totalTime += currentTime
        counter++
    }

    val averageSpeed = totalDistance / totalTime

    return averageSpeed
}
/**
 * A function to calculate the average speed of an aircraft.
 *
 * @param distance The distance covered by the aircraft (in kilometers).
 * @param time The total time taken by the aircraft (in hours).
 * @return The average speed of the aircraft (in kilometers per hour).
 */
fun calculateAverageSpeed(distance: Double, time: Double): Double {
/**
 * A function to calculate the average speed of an aircraft.
 *
 * @param distance The distance covered by the aircraft (in kilometers).
 * @param time The total time taken by the aircraft (in hours).
 * @return The average speed of the aircraft (in kilometers per hour).
 */
fun calculateAverageSpeed(distance: Double, time: Double): Double {

    if (distance <= 0 || time <= 0) {
        return 0.0
    }

    var totalDistance = 0.0
    var totalTime = 0.0
    var counter = 0

    while (true) {
        print("Enter the distance covered during the interval (in kilometers): ")
        val currentDistance = readLine()!!.toDouble()
        if (currentDistance == 0.0) {
            break
        }

        print("Enter the time taken for the interval (in hours): ")
        val currentTime = readLine()!!.toDouble()
        if (currentTime == 0.0) {
            break
        }

        totalDistance += currentDistance
        totalTime += currentTime
        counter++
    }

    val averageSpeed = totalDistance / totalTime

    return averageSpeed
}