Created
December 6, 2015 18:59
-
-
Save ygrenzinger/5e5634fbf8f69aa1e64d to your computer and use it in GitHub Desktop.
Solution for question 3 Koan of Edx F# Module 2
This file contains 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 readIntValue () : int = | |
let canparse, keyin = Int32.TryParse(Console.ReadLine()) | |
if canparse then keyin | |
else 0 | |
let readPerson (index : int) : (string * int) = | |
Console.WriteLine("info of person number {0}", index) | |
Console.WriteLine("Enter name: ") | |
let name = Console.ReadLine() | |
Console.WriteLine("Enter age: ") | |
let age = readIntValue() | |
( name, age ) | |
let messageDependingOfAge (name : string, age : int) : string = | |
if (age <= 13) then name + " is a kid or child" | |
elif (age < 20) then name + " is a teenager" | |
else name + " is no longer a teenager" | |
[<EntryPoint>] | |
let main argv = | |
Console.WriteLine("How many people will you enter ?") | |
let repeatCount = Console.ReadLine() | |
let repeatCount = int repeatCount | |
Console.WriteLine("You will enter {0} person(s)", repeatCount) | |
let listOfPerson = [ for i in 1..repeatCount do yield readPerson(i) ] | |
for (name, age) in listOfPerson do | |
Console.WriteLine(messageDependingOfAge(name, age)) | |
let c = Console.ReadKey() | |
0 // return an integer exit code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment