From 534827c9545f8fd22dd2ccd7c717960c5e718dbf Mon Sep 17 00:00:00 2001 From: sebastian Date: Tue, 7 Nov 2023 14:58:59 +0100 Subject: [PATCH] finished 69 --- Section7/69.go | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/Section7/69.go b/Section7/69.go index ed3164b..bffc358 100644 --- a/Section7/69.go +++ b/Section7/69.go @@ -79,13 +79,55 @@ // Using a for loop print out all the years from your birthday to the current year. // Use a variant of for loop where the post statement is moved inside the for block of code. +//package main +// +//import "fmt" +// +//func main() { +// for i := 1978; i <= 2023; i++ { +// fmt.Printf("%d ", i) +// } +// fmt.Println("") +//} + +// Coding Exercise #6 +// Consider the following Go program: https://play.golang.org/p/Wo5fIlurnX6 +/* +package main +import "fmt" + +func main() { + age := -9 + if age < 0 || age > 100 { + fmt.Println("Invalid Age") + } else if age < 18 { + fmt.Println("You are minor!") + } else if age == 18 { + fmt.Println("Congratulations! You've just become major!") + } else { + fmt.Println("You are major!") + } +} +Change the code and use a switch statement instead of an if statement. +*/ package main import "fmt" func main() { - for i := 1978; i <= 2023; i++ { - fmt.Printf("%d ", i) + age := 18 + + switch { + case age < 0 || age > 100: + fmt.Println("Invalid Age") + + case age < 18: + fmt.Println("You are minor!") + + case age == 18: + fmt.Println("Congratulations! You've just become major!") + + default: + fmt.Println("You are major!") } - fmt.Println("") }