Finished exercise and improved error handling

This commit is contained in:
raul 2024-01-19 09:23:55 +00:00
parent d9f17e78a3
commit c33ebb25f0
1 changed files with 25 additions and 15 deletions

View File

@ -1,32 +1,42 @@
package main package main
import "fmt" // TODO: figure out colored text
import (
"fmt"
)
func main() { func main() {
var numStar int var numStar int
var numShape int var numShape int
// TODO: Add error handling for star number
fmt.Println("How many stars do you want?") fmt.Println("How many stars do you want?")
fmt.Printf(" Stars: ") fmt.Printf(" Stars: ")
fmt.Scan(&numStar) fmt.Scan(&numStar)
fmt.Printf("\n") fmt.Printf("\n")
forShapes:
for {
fmt.Println("Which shape would you like?\n Line [1]\n Square [2]\n Flag [3]") fmt.Println("Which shape would you like?\n Line [1]\n Square [2]\n Flag [3]")
fmt.Printf("Shape: ") fmt.Printf("Shape: ")
fmt.Scan(&numShape) fmt.Scanln(&numShape)
fmt.Printf("\n")
switch numShape { switch numShape {
case 1: case 1:
println("Line") line(numStar)
break forShapes
case 2: case 2:
fmt.Println("Square") square(numStar)
break forShapes
case 3: case 3:
fmt.Println("Flag") flag(numStar)
break forShapes
default: default:
fmt.Println("Invalid input, please use either 1, 2 or 3.") fmt.Printf("\n[-] INVALID INPUT, please use either 1, 2 or 3.\n\n")
}
} }
//flag(numStar)
} }
func line(num int) { func line(num int) {