Skip to content

Commit

Permalink
solve(learngo): 12-switch
Browse files Browse the repository at this point in the history
  • Loading branch information
jestenough committed Aug 12, 2023
1 parent e2d8acf commit 78d30c1
Show file tree
Hide file tree
Showing 21 changed files with 134 additions and 598 deletions.
32 changes: 0 additions & 32 deletions collections/learngo/12-switch/01-one-case/main.go

This file was deleted.

37 changes: 0 additions & 37 deletions collections/learngo/12-switch/02-multiple-cases/main.go

This file was deleted.

38 changes: 0 additions & 38 deletions collections/learngo/12-switch/03-default-clause/main.go

This file was deleted.

31 changes: 0 additions & 31 deletions collections/learngo/12-switch/04-multiple-conditions/main.go

This file was deleted.

24 changes: 0 additions & 24 deletions collections/learngo/12-switch/05-bool-expressions/main.go

This file was deleted.

26 changes: 0 additions & 26 deletions collections/learngo/12-switch/06-fallthrough/01-without/main.go

This file was deleted.

28 changes: 0 additions & 28 deletions collections/learngo/12-switch/06-fallthrough/02-with/main.go

This file was deleted.

27 changes: 0 additions & 27 deletions collections/learngo/12-switch/07-short-switch/main.go

This file was deleted.

37 changes: 0 additions & 37 deletions collections/learngo/12-switch/08-parts-of-the-day/main.go

This file was deleted.

48 changes: 0 additions & 48 deletions collections/learngo/12-switch/09-when-to-use/main.go

This file was deleted.

44 changes: 44 additions & 0 deletions collections/learngo/12-switch/exercises/01-richter-scale/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

package main

import (
"fmt"
"os"
"strconv"
)

// ---------------------------------------------------------
// STORY
// You're curious about the richter scales. When reporters
Expand Down Expand Up @@ -71,4 +77,42 @@ package main
// ---------------------------------------------------------

func main() {
if len(os.Args) < 2 {
fmt.Println("Give me the magnitude of the earthquake.")
return
}

var (
value float64
err error
)

if value, err = strconv.ParseFloat(os.Args[1], 8); err != nil {
fmt.Println("I couldn't get that, sorry.")
return
}

var valueForMessage string
switch r := value; {
case r < 2:
valueForMessage = "micro"
case r >= 2 && r < 3:
valueForMessage = "very minor"
case r >= 3 && r < 4:
valueForMessage = "minor"
case r >= 4 && r < 5:
valueForMessage = "light"
case r >= 5 && r < 6:
valueForMessage = "moderate"
case r >= 6 && r < 7:
valueForMessage = "strong"
case r >= 7 && r < 8:
valueForMessage = "major"
case r >= 8 && r < 10:
valueForMessage = "great"
default:
valueForMessage = "massive"
}

fmt.Printf("%.2f is %s\n", value, valueForMessage)
}
Loading

0 comments on commit 78d30c1

Please sign in to comment.