# Arrays for items and quantities items <- character(0) quantities <- numeric(0) # Function to add item add_item <- function(item, quantity) { items <<- c(items, item) quantities <<- c(quantities, quantity) cat("Item added.\n") } # Function to update quantity update_quantity <- function(item, quantity) { if (item %in% items) { quantities[which(items == item)] <<- quantity cat("Quantity updated.\n") } else cat("Item not found.\n") } # Function to display inventory display_inventory <- function() { for (i in 1:length(items)) { cat(items[i], ":", quantities[i], "\n") } } # Main program loop repeat { choice <- as.integer(readline("1. Add 2. Update 3. Display 4. Exit: ")) if (choice == 1) { item <- readline("Item: ") quantity <- as.integer(readline("Quantity: ")) add_item(item, quantity) } else if (choice == 2) { item <- readline("Item: ") quantity <- as.integer(readline("New Quantity: ")) update_quantity(item, quantity) } else if (choice == 3) display_inventory() else if (choice == 4) break else cat("Invalid option.\n") }