Skip to content

Instantly share code, notes, and snippets.

@OakRaven
Created October 10, 2015 03:02
Show Gist options
  • Save OakRaven/2d065693bf35ea273986 to your computer and use it in GitHub Desktop.
Save OakRaven/2d065693bf35ea273986 to your computer and use it in GitHub Desktop.
open System
let rec getPeopleCount() : int =
Console.Write("How many people? ")
let countinput = Console.ReadLine()
let canparse, count = Int32.TryParse(countinput)
if canparse then
if count <= 0 then
Console.WriteLine("** Please enter a number, greater than 0 **")
getPeopleCount()
else
count
else
Console.WriteLine("** Please enter a number, greater than 0 **")
getPeopleCount()
let getPersonsName(index : int) : string =
Console.Write("{0}:\tPlease enter person's name: ", index)
Console.ReadLine()
let rec getPersonsAge(name : string) : int =
Console.Write("\tHow old is this {0}: ", name)
let ageinput = Console.ReadLine()
let canparse, age = Int32.TryParse(ageinput)
if canparse then
if age <= 0 then
Console.WriteLine("\t** Please enter an age greater than 0 **")
getPersonsAge name
else
age
else
Console.WriteLine("\t** Please enter an age greater than 0 **")
getPersonsAge name
[<EntryPoint>]
let main argv =
let count = getPeopleCount()
for index = 1 to count do
let name = getPersonsName index
let age = getPersonsAge name
if age >= 20 then
Console.WriteLine("\t{0} is no longer a teenager.\n", name)
elif age > 12 then
Console.WriteLine("\t{0} is a teenager.\n", name)
else
Console.WriteLine("\t{0} is a child.\n", name)
Console.ReadKey()
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment