Assignment1
Assignment1
Function DisplayMenu()
Print "Inventory Management System"
Print "1. Add New Item"
Print "2. Update Item Quantity"
Print "3. Generate Inventory Report"
Print "4. Exit"
Print "Enter your choice: "
End Function
Function AddNewItem()
Try
Print "Enter Item Name: "
item_name <- Input()
Print "Enter Item Quantity: "
quantity <- Integer(Input())
If quantity < 0 Then
Throw Exception("Quantity cannot be negative")
End If
Inventory.append([item_name, quantity])
Print "Item successfully added!"
Catch Exception as error
Print "Error: " + error.message
End Try
End Function
Function UpdateQuantity()
Try
Print "Enter Item Name to Update: "
item_name <- Input()
item_found <- False
For Each item in Inventory
If item[0] == item_name Then
Print "Current Quantity: " + item[1]
Print "Enter New Quantity: "
new_quantity <- Integer(Input())
If new_quantity < 0 Then
Throw Exception("Quantity cannot be negative")
End If
item[1] <- new_quantity
item_found <- True
Print "Quantity updated successfully!"
End If
End For
If item_found == False Then
Print "Item not found."
End If
Catch Exception as error
Print "Error: " + error.message
End Try
End Function
Repeat
DisplayMenu()
choice <- Integer(Input())
Switch choice
Case 1:
AddNewItem()
Break
Case 2:
UpdateQuantity()
Break
Case 3:
GenerateReport()
Break
Case 4:
Print "Exiting System. Goodbye!"
Exit Program
Default:
Print "Invalid choice. Please try again."
End Repeat