Last active
July 10, 2016 12:32
-
-
Save derekmorr/6f0a10843bfff5b76eb6 to your computer and use it in GitHub Desktop.
F# MOOC week 2 assignment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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