From c33ebb25f07cfc33393d15b0cd26004827a206cd Mon Sep 17 00:00:00 2001 From: raul Date: Fri, 19 Jan 2024 09:23:55 +0000 Subject: [PATCH] Finished exercise and improved error handling --- star-shapes/main.go | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/star-shapes/main.go b/star-shapes/main.go index b3b44d2..c807c62 100644 --- a/star-shapes/main.go +++ b/star-shapes/main.go @@ -1,32 +1,42 @@ package main -import "fmt" +// TODO: figure out colored text + +import ( + "fmt" +) func main() { var numStar int var numShape int + // TODO: Add error handling for star number fmt.Println("How many stars do you want?") fmt.Printf(" Stars: ") fmt.Scan(&numStar) fmt.Printf("\n") - fmt.Println("Which shape would you like?\n Line [1]\n Square [2]\n Flag [3]") - fmt.Printf("Shape: ") - fmt.Scan(&numShape) - - switch numShape { - case 1: - println("Line") - case 2: - fmt.Println("Square") - case 3: - fmt.Println("Flag") - default: - fmt.Println("Invalid input, please use either 1, 2 or 3.") +forShapes: + for { + fmt.Println("Which shape would you like?\n Line [1]\n Square [2]\n Flag [3]") + fmt.Printf("Shape: ") + fmt.Scanln(&numShape) + fmt.Printf("\n") + switch numShape { + case 1: + line(numStar) + break forShapes + case 2: + square(numStar) + break forShapes + case 3: + flag(numStar) + break forShapes + default: + fmt.Printf("\n[-] INVALID INPUT, please use either 1, 2 or 3.\n\n") + } } - //flag(numStar) } func line(num int) {