F# Basic Function Sample 1

The Code

open System

let face (x:int) :string = 
    let remainder = x % 13
    if remainder = 1 then "Ace"
    elif remainder = 11 then "Jack"
    elif remainder = 12 then "Queen"
    elif remainder = 0 then "King"
    else string remainder

let suit (x:int) :string = 
    if x < 13 then "Hearts"
    elif x > 13 && x < 27 then "Diamonds"
    elif x > 26 && x < 40 then "Clubs"
    else "Spades"

let main argv =

    let mutable keeplooping = true

    while keeplooping do
        printfn "Enter Card Number"
        let x = Console.ReadLine()
        printfn "%s of %s" (face (int x)) (suit (int x))

    exit 100

No explanation as yet, I'm still getting to grips with this myself.


Reader's Comments

Post Your Comment Posts/Links Rules



Add a RELEVANT link (not required)

Upload an image (not required)

No uploaded image
Real person number
Please enter the above number below

Admin Ren's Biking Blog