Skip to content

Instantly share code, notes, and snippets.

@derekmorr
Last active July 10, 2016 12:32
Show Gist options
  • Save derekmorr/6f0a10843bfff5b76eb6 to your computer and use it in GitHub Desktop.
Save derekmorr/6f0a10843bfff5b76eb6 to your computer and use it in GitHub Desktop.
F# MOOC week 2 assignment
open System
let readConsoleValue prompt =
printf "%s: " prompt
Console.ReadLine()
let classifyAge name age =
if age >= 20 then
sprintf "%s is no longer a teenager" name
elif (age < 20 && age > 13) then
sprintf "%s is a teenager" name
else
sprintf "%s is a kid or child" name
let handleOnePass () =
let name = readConsoleValue "What's your name?"
let canparse, age = Int32.TryParse(readConsoleValue "What's your age?")
if canparse then
let output = classifyAge name age
printf "%s\n" output
else
printf "Unable to parse age.\n"
let keepGoing () =
let v = readConsoleValue "Do you wish to continue? (Y/N)"
if v.ToLower() = "y" then
true
else
false
[<EntryPoint>]
let main argv =
let mutable keepRunning = true
while keepRunning do
handleOnePass ()
keepRunning <- keepGoing ()
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment