Visual F# 100 Examples: Example 8 to 10

Problem: Make a console application that will accept five numbers and display the sum.
  1. open System  
  2. //change the title to Add Five Numbers  
  3. System.Console.Title<-"Add Five Numbers "  
  4. //change the foreground color to cyan  
  5. Console.ForegroundColor<-ConsoleColor.Cyan  
  6. printfn "\t\t\tEnter the first number:"  
  7. let intnum1=Convert.ToInt32(System.Console.ReadLine())  
  8. printfn "\t\t\tEnter the second number:"  
  9. let intnum2=Convert.ToInt32(System.Console.ReadLine())  
  10. printfn "\t\t\tEnter the third number:"  
  11. let intnum3=Convert.ToInt32(System.Console.ReadLine())  
  12. printfn "\t\t\tEnter the fourth number:"  
  13. let intnum4=Convert.ToInt32(System.Console.ReadLine())  
  14. printfn "\t\t\tEnter the fifth number:"  
  15. let intnum5=Convert.ToInt32(System.Console.ReadLine())  
  16. let  intsum=intnum1+ intnum2 + intnum3 + intnum4 + intnum5  
  17. printfn "\t\t\tThe sum is:%i" intsum  
Problem: Make a console application that will ask the power transmitted and power received then display the power loss value.
  1. open System  
  2. //change the title to Calculate Power Loss  
  3. System.Console.Title<-"Calculate Power Loss "  
  4. //change the foreground color to cyan  
  5. Console.ForegroundColor<-ConsoleColor.Cyan  
  6. printfn "\t\t\t\tPower transmitted:"  
  7. let dblpowertrans=Convert.ToDouble(System.Console.ReadLine())  
  8. printfn "\t\t\tPower recieved:"  
  9. let dblpowerrec=Convert.ToDouble(System.Console.ReadLine())  
  10. let dblpowerloss= dblpowertrans/ dblpowerrec  
  11. printfn "\t\t\t Power loss:%f " dblpowerloss  
Problem: Develop a console application that will ask the base value and height value then display the volume of a pyramid.
  1. open System  
  2. //change the title to Volume of a Pyramid  
  3. System.Console.Title<-" Volume of a Pyramid"  
  4. //change the foreground color to cyan  
  5. Console.ForegroundColor<-ConsoleColor.Cyan  
  6. printfn "\t\t\tBase value:"  
  7. let dblbase=Convert.ToDouble(System.Console.ReadLine())  
  8. printfn "\t\t\tHeight value:"  
  9. let dblheight=Convert.ToDouble(System.Console.ReadLine())  
  10. let  dblvolume=(dblbase*dblheight)/3.0  
  11. printfn "\t\t\tVolume of a pyramid:%f" dblvolume  

Visual F# 100 Examples: Example Number 7

So far I have been sharing to you guys some examples of Window Based application in Visual F#. This time, for variation sake lets make some console application:

Problem: Make a simple console application mind reader game.
  1. open System  
  2. //change the title to Simple Mind Reader Game  
  3. System.Console.Title<-"Simple Mind Reader Game"  
  4. //change the foreground color to cyan  
  5. Console.ForegroundColor<-ConsoleColor.Cyan  
  6. //dislay the game title screen  
  7. printfn "\t\t\t Mind Reader Game"  
  8. printfn "\t\t\tPress enter to continue..."  
  9. //waits for a keypress from the user  
  10. System.Console.ReadLine()|>ignore  
  11. System.Console.Clear()  
  12. //the following does the game action sequence  
  13. printfn "\t\t\t Think of a five-digit number that has five unique numbers(Eg. 12345)"  
  14. printfn "\t\t\tPress enter to continue..."  
  15. System.Console.ReadLine()|>ignore  
  16. System.Console.Clear()  
  17.   
  18. printfn "\t\t\t Reverse the numbers then subtract the smaller number from the larger number(Eg.54321- 12345)"  
  19. printfn "\t\t\tPress enter to continue..."  
  20. System.Console.ReadLine()|>ignore  
  21. System.Console.Clear()  
  22.   
  23. printfn "\t\t\t Add 10000 to the difference"  
  24. printfn "\t\t\t Press enter to continue..."  
  25. System.Console.ReadLine()|>ignore  
  26. System.Console.Clear()  
  27.   
  28. printfn "\t\t\tVisualize the sum while I try to read your mind."  
  29. printfn "\t\t\tPress enter to continue..."  
  30. System.Console.ReadLine()|>ignore  
  31. System.Console.Clear()  
  32.   
  33. printfn "\t\t\tThe sum is…"  
  34. printfn "\t\t\tPress enter to continue..."  
  35. System.Console.ReadLine()|>ignore  
  36. System.Console.Clear()  
  37.   
  38. printfn "\t\t\tThe sum is…"  
  39. printfn "\t\t\tPress enter to continue..."  
  40. System.Console.ReadLine()|>ignore  
  41. System.Console.Clear()  
  42.   
  43. printfn "\t\t\tThe sum is…"  
  44. printfn "\t\t\tPress enter to continue..."  
  45. System.Console.ReadLine()|>ignore  
  46. System.Console.Clear()  
  47.   
  48. printfn "\t\t\t51976"