Skip to content

Instantly share code, notes, and snippets.

@ecounysis
Created October 8, 2015 16:48
Show Gist options
  • Save ecounysis/371f79dbdffda3746107 to your computer and use it in GitHub Desktop.
Save ecounysis/371f79dbdffda3746107 to your computer and use it in GitHub Desktop.
open System
let printLines n =
for s = 1 to n do
Console.WriteLine()
n
let getInt x =
let succ = Int32.TryParse(x)
match succ with
| (true, x) -> Some(x)
| (false, _) -> None
let getPerson () =
printLines 200 |> ignore
Console.WriteLine("Enter name: ")
let name = Console.ReadLine()
let mutable age = -1
while age < 0 do
printfn "Enter age of %s: " name
let tempAge = Console.ReadLine()
age <- match getInt tempAge with
| Some(x) -> x
| None -> -1
if age < 0 then Console.WriteLine("\nInvalid age") |> ignore
(name, age)
let keepGoingFunction (prompt:string) trueValues =
Console.WriteLine(prompt)
let want = Console.ReadKey()
List.exists (fun (x:string) -> x.ToUpper() = want.Key.ToString().ToUpper()) trueValues
let getPeople () =
let mutable keepGoing = true
let mutable people = []
while keepGoing do
people <- List.append people [getPerson()]
keepGoing <- keepGoingFunction "Enter another person (y/n)" ["y"]
people
let showPeople people =
printLines 200 |> ignore
for person in people do
let name, age = person
let description = if age >= 20 then name + " is no longer a teenager."
elif age >= 13 then name + " is a teenager."
else name + " is a kid."
printf "Name: %s\n" name
printf "Age: %d\n" age
printf "%s\n\n" description
[<EntryPoint>]
let main argv =
let people = getPeople()
showPeople people |> ignore
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment