add homework for 2021-11-26

This commit is contained in:
Amolith 2021-11-22 16:38:01 -05:00
parent 988a239192
commit 02c747fe29
Signed by: Amolith
GPG Key ID: 5548AD9930655715
1 changed files with 54 additions and 0 deletions

54
2021-11-26/main.go Normal file
View File

@ -0,0 +1,54 @@
// 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()
}