/**
 * In this exercise, you are an electrician trying to inventory and update your tools. Complete the code to
 * continuously prompt the electrician to enter a tool name and its quantity until they choose to stop.
 * The electrician can either add a new tool or update the quantity of an existing tool.
 *
 * @param electricianTools A dictionary containing the current tools and their quantities
 * @return A dictionary containing the updated tools and their quantities after the user stops adding/editing tools
 */
fun changingElementsInfiniteLoop(electricianTools: MutableMap<String, Int>): Map<String, Int> {

    while (true) {
        println("What would you like to do?")
        println("1. Add a new tool")
        println("2. Update the quantity of an existing tool")
        println("0. Stop adding/editing tools")
        val choice = readLine()!!.toInt()
        println()

        when (choice) {
            1 -> {
                print("Enter the name of the new tool: ")
                val toolName = readLine()!!
                print("Enter the quantity of the new tool: ")
                val toolQuantity = readLine()!!.toInt()
                electricianTools[toolName] = toolQuantity
            }
            2 -> {
                print("Enter the name of the existing tool: ")
                val toolName = readLine()!!
                if (electricianTools.containsKey(toolName)) {
                    print("Enter the new quantity for $toolName: ")
                    val toolQuantity = readLine()!!.toInt()
                    electricianTools[toolName] = toolQuantity
                } else {
                    println("Tool not found. Please add it as a new tool.")
                }
            }
            0 -> break
            else -> println("Invalid choice. Please try again.")
        }
    }
    return electricianTools
}
/**
 * In this exercise, you are an electrician trying to inventory and update your tools. Complete the code to
 * continuously prompt the electrician to enter a tool name and its quantity until they choose to stop.
 * The electrician can either add a new tool or update the quantity of an existing tool.
 *
 * @param electricianTools A dictionary containing the current tools and their quantities
 * @return A dictionary containing the updated tools and their quantities after the user stops adding/editing tools
 */
fun changingElementsInfiniteLoop(electricianTools: MutableMap<String, Int>): Map<String, Int> {
/**
 * In this exercise, you are an electrician trying to inventory and update your tools. Complete the code to
 * continuously prompt the electrician to enter a tool name and its quantity until they choose to stop.
 * The electrician can either add a new tool or update the quantity of an existing tool.
 *
 * @param electricianTools A dictionary containing the current tools and their quantities
 * @return A dictionary containing the updated tools and their quantities after the user stops adding/editing tools
 */
fun changingElementsInfiniteLoop(electricianTools: MutableMap<String, Int>): Map<String, Int> {

    while (true) {
        println("What would you like to do?")
        println("1. Add a new tool")
        println("2. Update the quantity of an existing tool")
        println("0. Stop adding/editing tools")
        val choice = readLine()!!.toInt()
        println()

        when (choice) {
            1 -> {
                print("Enter the name of the new tool: ")
                val toolName = readLine()!!
                print("Enter the quantity of the new tool: ")
                val toolQuantity = readLine()!!.toInt()
                electricianTools[toolName] = toolQuantity
            }
            2 -> {
                print("Enter the name of the existing tool: ")
                val toolName = readLine()!!
                if (electricianTools.containsKey(toolName)) {
                    print("Enter the new quantity for $toolName: ")
                    val toolQuantity = readLine()!!.toInt()
                    electricianTools[toolName] = toolQuantity
                } else {
                    println("Tool not found. Please add it as a new tool.")
                }
            }
            0 -> break
            else -> println("Invalid choice. Please try again.")
        }
    }
    return electricianTools
}