code_with_ki/2021-11-26/main.go

55 lines
899 B
Go

// SPDX-FileCopyrightText: 2021 Amolith <amolith@secluded.site>
//
// 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()
}