/**
 * This function takes the number of stairs as input and calculates
 * the required length and height dimensions for constructing a staircase.
 *
 * @param numStairs The number of stairs in the staircase.
 * @return A Pair containing the length and height dimensions of the staircase.
 */
fun calculateStaircaseDimensions(numStairs: Int): Pair<Double, Double>? {

    try {
        print("Enter the desired width of each stair (in meters): ")
        val width = readLine()?.toDouble() ?: 0.0
        require(width > 0) { "Width must be a positive number." }

        var length = 0.0
        var height = 0.0
        var count = 1

        while (count <= numStairs) {
            try {
                print("Enter the length of stair $count (in meters): ")
                length += readLine()?.toDouble() ?: 0.0
                require(length > 0) { "Length must be a positive number." }

                print("Enter the height of stair $count (in meters): ")
                height += readLine()?.toDouble() ?: 0.0
                require(height > 0) { "Height must be a positive number." }

                count++
            } catch (e: IllegalArgumentException) {
                println(e.message)
                return null
            } catch (e: NumberFormatException) {
                println("Invalid input. Please enter a valid number.")
                return null
            }
        }

        return Pair(length, height)
    } catch (e: Exception) {
        println("An error occurred: ${e.message}")
        return null
    }
}
/**
 * This function takes the number of stairs as input and calculates
 * the required length and height dimensions for constructing a staircase.
 *
 * @param numStairs The number of stairs in the staircase.
 * @return A Pair containing the length and height dimensions of the staircase.
 */
fun calculateStaircaseDimensions(numStairs: Int): Pair<Double, Double>? {
/**
 * This function takes the number of stairs as input and calculates
 * the required length and height dimensions for constructing a staircase.
 *
 * @param numStairs The number of stairs in the staircase.
 * @return A Pair containing the length and height dimensions of the staircase.
 */
fun calculateStaircaseDimensions(numStairs: Int): Pair<Double, Double>? {

    try {
        print("Enter the desired width of each stair (in meters): ")
        val width = readLine()?.toDouble() ?: 0.0
        require(width > 0) { "Width must be a positive number." }

        var length = 0.0
        var height = 0.0
        var count = 1

        while (count <= numStairs) {
            try {
                print("Enter the length of stair $count (in meters): ")
                length += readLine()?.toDouble() ?: 0.0
                require(length > 0) { "Length must be a positive number." }

                print("Enter the height of stair $count (in meters): ")
                height += readLine()?.toDouble() ?: 0.0
                require(height > 0) { "Height must be a positive number." }

                count++
            } catch (e: IllegalArgumentException) {
                println(e.message)
                return null
            } catch (e: NumberFormatException) {
                println("Invalid input. Please enter a valid number.")
                return null
            }
        }

        return Pair(length, height)
    } catch (e: Exception) {
        println("An error occurred: ${e.message}")
        return null
    }
}