add homework for 2021-11-26
This commit is contained in:
parent
988a239192
commit
02c747fe29
|
@ -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()
|
||||||
|
}
|
Loading…
Reference in New Issue