re: Daily Challenge #68 - Grade Book VIEW POST

FULL DISCUSSION
 

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)
}
code of conduct - report abuse