jecxjo

DEV207.1x - Module 2 Question 3

Oct 13th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.80 KB | None | 0 0
  1. (*
  2.  * edX course: Microsoft: DEV207.1x Programming in F#
  3.  * Assignment: Module 2: Conditionals and Loops - Question 3
  4.  * Author: jecxjo
  5.  *)
  6. open System
  7.  
  8. let rec info i =
  9.   printfn "Person %d" i
  10.   printf "Name: "
  11.   let name = Console.ReadLine()
  12.   printf "Age: "
  13.   let b,age = Int32.TryParse(Console.ReadLine());
  14.   if b && name.Length > 0 then
  15.     if age >= 20 then
  16.       printfn "%s is no longer a teenager" name
  17.     elif age < 20 && age >= 13 then
  18.       printfn "%s is a  teenager" name
  19.     else
  20.       printfn "%s is a child" name
  21.   else
  22.     printfn "Error entering info"
  23.     info i
  24.  
  25. [<EntryPoint>]
  26. let main _ =
  27.   printf "Enter number of people: "
  28.   let b,count = Int32.TryParse(Console.ReadLine())
  29.   if b then
  30.     for i = 1 to count do
  31.       info i
  32.   else
  33.     printf "Not a number"
  34.   0
Advertisement
Add Comment
Please, Sign In to add comment