diff --git a/2021-11-26/main.go b/2021-11-26/main.go new file mode 100644 index 0000000..5e571af --- /dev/null +++ b/2021-11-26/main.go @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: 2021 Amolith +// +// SPDX-License-Identifier: BSD-3-Clause + +package main + +import ( + "fmt" + "os" +) + +var ( + fridgeItems []string + fridgeCount []int +) + +func main() { + menu() +} + +func menu() { + fmt.Println(`- [a]dd an item to your fridge +- [l]ist the items currently in your fridge +- [e]xit`) + fmt.Print("What would you like to do?: ") + var s string + fmt.Scanln(&s) + if s == "a" { + add() + } else if s == "l" { + list() + } else if s == "e" { + os.Exit(0) + } +} + +func add() { + fmt.Print("What would you like to add to your fridge?: ") + var item string + fmt.Scanln(&item) + fridgeItems = append(fridgeItems, item) + fmt.Print("How many would you like added?: ") + var count int + fmt.Scanln(&count) + fridgeCount = append(fridgeCount, count) + menu() +} + +func list() { + for i, item := range fridgeItems { + fmt.Printf("x%d %s\n", fridgeCount[i], item) + } + menu() +}