Advertisement
olemis

Edx - F# - Homework Conditionals

Nov 5th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.09 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.org
  2. // See the 'F# Tutorial' project for more help.
  3.  
  4. // The code for both koan and problem are included in this file
  5. // Indented code available at
  6.  
  7. open System
  8.  
  9. [<EntryPoint>]
  10. let main argv =
  11.     // Koan
  12.  
  13. //    let dosomethingrandom x =
  14. //        if x == 0 then Console.WriteLine(1)
  15. //        else dosomethingrandom (x - 1) * x
  16.  
  17.     let rec dosomethingrandom x =
  18.         if x = 0 then 1
  19.         else x * dosomethingrandom (x - 1)
  20.  
  21.     let calc0 = dosomethingrandom 0
  22.     let calc12 = dosomethingrandom 12
  23.     printfn "%d %d" calc0 calc12
  24.  
  25.     // Problem
  26.     printf "Enter name "
  27.     let name = Console.ReadLine()
  28.     printf "Enter age "
  29.     let isvalid, age = Int32.TryParse(Console.ReadLine())
  30.     if isvalid then
  31.         let message = if age >= 20 then name + " is not a teenager"
  32.                       elif age < 13 then
  33.                         name + " is a kid or child"
  34.                       else
  35.                         name + " is a teenager"
  36.         printfn "%s" message
  37.     Console.ReadKey()
  38.     0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement