add: switch statement exercises

This commit is contained in:
Inanc Gumus
2018-10-27 17:57:50 +03:00
parent 1d1280d76b
commit 3c374e38dc
11 changed files with 17 additions and 11 deletions

View File

@ -0,0 +1,53 @@
// For more tutorials: https://blog.learngoprogramming.com
//
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
package main
import (
"fmt"
"os"
)
func main() {
args := os.Args
if len(args) != 2 {
fmt.Println("Tell me the magnitude of the earthquake in human terms.")
return
}
var richter string
desc := args[1]
switch desc {
case "micro":
richter = "less than 2.0"
case "very minor":
richter = "2 - 2.9"
case "minor":
richter = "3 - 3.9"
case "light":
richter = "4 - 4.9"
case "moderate":
richter = "5 - 5.9"
case "strong":
richter = "6 - 6.9"
case "major":
richter = "7 - 7.9"
case "great":
richter = "8 - 8.9"
case "massive":
richter = "10+"
default:
richter = "unknown"
}
fmt.Printf(
"%s's richter scale is %s\n",
desc, richter,
)
}