/**
 * This exercise focuses on using the addition assignment operator and basic for loop to add cooking ingredients multiple times in a Chef's recipe.
 */
fun addCookingIngredients(numIterations: Int) {

    // Initialize a variable to store the final result
    val recipe = mutableListOf<String>()

    // Loop through the ingredients for the specified number of iterations
    repeat(numIterations) {
        // Prompt the Chef to enter an ingredient to add
        print("Chef, please enter an ingredient to add to the recipe: ")
        val ingredient = readLine()

        // Create a variable to store the ingredient quantity
        var quantity = 1

        // Prompt the Chef to enter the quantity for the ingredient
        while (true) {
            try {
                print("Chef, please enter the quantity of the ingredient: ")
                quantity = readLine()?.toInt() ?: 1
                break
            } catch (e: NumberFormatException) {
                println("Invalid input. Please enter a valid quantity.")
            }
        }

        // Use the addition assignment operator to add the ingredient and its quantity to the recipe
        repeat(quantity) {
            recipe.add(ingredient ?: "")
        }
    }

    // Print the final recipe
    println("Chef, here is the final recipe after adding the ingredients:")
    recipe.forEachIndexed { index, ingredient ->
        println("${index + 1}. $ingredient")
    }
}
/**
 * This exercise focuses on using the addition assignment operator and basic for loop to add cooking ingredients multiple times in a Chef's recipe.
 */
fun addCookingIngredients(numIterations: Int) {
/**
 * This exercise focuses on using the addition assignment operator and basic for loop to add cooking ingredients multiple times in a Chef's recipe.
 */
fun addCookingIngredients(numIterations: Int) {

    // Initialize a variable to store the final result
    val recipe = mutableListOf<String>()

    // Loop through the ingredients for the specified number of iterations
    repeat(numIterations) {
        // Prompt the Chef to enter an ingredient to add
        print("Chef, please enter an ingredient to add to the recipe: ")
        val ingredient = readLine()

        // Create a variable to store the ingredient quantity
        var quantity = 1

        // Prompt the Chef to enter the quantity for the ingredient
        while (true) {
            try {
                print("Chef, please enter the quantity of the ingredient: ")
                quantity = readLine()?.toInt() ?: 1
                break
            } catch (e: NumberFormatException) {
                println("Invalid input. Please enter a valid quantity.")
            }
        }

        // Use the addition assignment operator to add the ingredient and its quantity to the recipe
        repeat(quantity) {
            recipe.add(ingredient ?: "")
        }
    }

    // Print the final recipe
    println("Chef, here is the final recipe after adding the ingredients:")
    recipe.forEachIndexed { index, ingredient ->
        println("${index + 1}. $ingredient")
    }
}