My first stab at writing something other than "Hello World!" in golang:
package main import ( "fmt" "math" ) func grade(x, y, z float64) string { mean := float64((x + y + z) / 3) grade := "" if mean >= 90 && mean <= 100 { grade = "A" } else if mean >= 80 && mean < 90 { grade = "B" } else if mean >= 70 && mean < 80 { grade = "C" } else if mean >= 60 && mean < 70 { grade = "D" } else if mean >= 0 && mean < 60 { grade = "F" } if math.Mod(mean, 10.0) < 5 && grade != "F" { grade += "-" } else if math.Mod(mean, 10.0) >= 5 && grade != "F" { grade += "+" } return grade } func main() { //output := grade(64, 55, 92) //output := grade(99, 89, 93) output := grade(33, 99, 95) fmt.Println(output) }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My first stab at writing something other than "Hello World!" in golang: