Visual F# 100 Examples: Example 12 and 13

This is the continuation of our planned 100 Visual F# examples. By the way, the bugs in examples number 7 to 11 had been fixed. My apologies, I should’nt have written those without using Visual F# compiler:)


Problem: Make a console application that will asks the user to enter the day that he was born and display his character or future based on the famous nursery rhyme written in England, “Monday’s Child”.

  1. open System  
  2. //changes the console application title  
  3. System.Console.Title<-"Tell the Future"  
  4. //adds foreground color  
  5. System.Console.ForegroundColor<-ConsoleColor.Cyan  
  6. printfn "What day were you born?"  
  7. let strday=System.Console.ReadLine()  
  8. //clears the screen  
  9. System.Console.Clear()  
  10. //converts the inputs to lowercase then compare it our  
  11. //specified values  
  12. if strday.ToLower()="monday" then  
  13.     printfn "Monday's child is fair of face"  
  14. else if strday.ToLower()="tuesday" then  
  15.     printfn "Tuesday's child is full of grace"  
  16. else if strday.ToLower()="wednesday" then  
  17.     printfn "Wednesday's child is full of woe"  
  18. else if strday.ToLower()="thursday" then  
  19.     printfn "Thurdays's child has far to go"  
  20. else if strday.ToLower()="friday" then  
  21.     printfn "Friday's child is loving and giving"  
  22. else if strday.ToLower()="saturday" then  
  23.     printfn "Saturday's child works hard for a living"  
  24. else if strday.ToLower()="sunday" then  
  25.     printfn "Sunday's child is bonny and blithe and good and gay"  
  26. else  
  27.     printfn "Invalid input"  
Problem: Develop a console application that will asks the wind speed in kilometer per hour(kph) and display its equivalent Philippine Storm Signal number.
  1. open System  
  2. //changes the console application title  
  3. System.Console.Title<-"Determine Storm Signal Number"  
  4. //adds foreground color  
  5. System.Console.ForegroundColor<-ConsoleColor.Cyan  
  6. printfn "Enter wind speed(kph):"  
  7. let intspeed=Convert.ToInt32(System.Console.ReadLine())  
  8. //clears the screen  
  9. System.Console.Clear()  
  10. //if the wind speed ranges from 30 to 60  
  11. if intspeed>=30 && intspeed<=60 then  
  12.     printfn "Storm signal number 1"  
  13. //if the wind speed ranges from 61 to 100  
  14. else if intspeed>60 && intspeed<=100 then  
  15.     printfn "Storm signal number 2"  
  16. //if the wind speed ranges from 101 to 185  
  17. else if intspeed>100 && intspeed<=185 then  
  18.     printfn "Storm signal number 3"  
  19. //if the wind speed is greater than 185  
  20. else if intspeed>185 then  
  21. printfn "Storm signal number 4"  
  22. else   
  23. printfn "Invalid input"