re: Daily Challenge #68 - Grade Book VIEW POST

FULL DISCUSSION
 

F#:

module DailyChallenge

let private gradeLetter mean =
    if mean < 60. then 'F'
    else if mean < 70. then 'D'
    else if mean < 80. then 'C'
    else if mean < 90. then 'B'
    else 'A'

let gradeSign mean =
    match int mean % 10 with
    | x when x > 5 -> "+"
    | 5 -> ""
    | _ -> "-"

let grade grade1 grade2 grade3 = 
    let mean = float (grade1 + grade2 + grade3) / 3.
    sprintf "%c%s" (gradeLetter mean) (gradeSign mean)

Tests:

module DailyChallengeTest

open FsUnit.Xunit
open Xunit
open DailyChallenge

[<Fact>]
let ``C-``() = grade 64 55 92 |> should equal "C-"

[<Fact>]
let ``A-``() = grade 99 89 93 |> should equal "A-"

[<Fact>]
let ``C+``() = grade 33 99 98 |> should equal "C+"

[<Fact>]
let ``C``() = grade 64 70 92 |> should equal "C"

[<Fact>]
let ``F``() = grade 55 55 55 |> should equal "F"
code of conduct - report abuse