Visual F# 100 Examples: Example 8 to 10

Problem: Make a console application that will accept five numbers and display the sum.
open System
//change the title to Add Five Numbers
System.Console.Title<-"Add Five Numbers "
//change the foreground color to cyan
Console.ForegroundColor<-ConsoleColor.Cyan
printfn "\t\t\tEnter the first number:"
let intnum1=Convert.ToInt32(System.Console.ReadLine())
printfn "\t\t\tEnter the second number:"
let intnum2=Convert.ToInt32(System.Console.ReadLine())
printfn "\t\t\tEnter the third number:"
let intnum3=Convert.ToInt32(System.Console.ReadLine())
printfn "\t\t\tEnter the fourth number:"
let intnum4=Convert.ToInt32(System.Console.ReadLine())
printfn "\t\t\tEnter the fifth number:"
let intnum5=Convert.ToInt32(System.Console.ReadLine())
let  intsum=intnum1+ intnum2 + intnum3 + intnum4 + intnum5
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.
open System
//change the title to Calculate Power Loss
System.Console.Title<-"Calculate Power Loss "
//change the foreground color to cyan
Console.ForegroundColor<-ConsoleColor.Cyan
printfn "\t\t\t\tPower transmitted:"
let dblpowertrans=Convert.ToDouble(System.Console.ReadLine())
printfn "\t\t\tPower recieved:"
let dblpowerrec=Convert.ToDouble(System.Console.ReadLine())
let dblpowerloss= dblpowertrans/ dblpowerrec
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.
open System
//change the title to Volume of a Pyramid
System.Console.Title<-" Volume of a Pyramid"
//change the foreground color to cyan
Console.ForegroundColor<-ConsoleColor.Cyan
printfn "\t\t\tBase value:"
let dblbase=Convert.ToDouble(System.Console.ReadLine())
printfn "\t\t\tHeight value:"
let dblheight=Convert.ToDouble(System.Console.ReadLine())
let  dblvolume=(dblbase*dblheight)/3.0
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.
open System
//change the title to Simple Mind Reader Game
System.Console.Title<-"Simple Mind Reader Game"
//change the foreground color to cyan
Console.ForegroundColor<-ConsoleColor.Cyan
//dislay the game title screen
printfn "\t\t\t Mind Reader Game"
printfn "\t\t\tPress enter to continue..."
//waits for a keypress from the user
System.Console.ReadLine()|>ignore
System.Console.Clear()
//the following does the game action sequence
printfn "\t\t\t Think of a five-digit number that has five unique numbers(Eg. 12345)"
printfn "\t\t\tPress enter to continue..."
System.Console.ReadLine()|>ignore
System.Console.Clear()

printfn "\t\t\t Reverse the numbers then subtract the smaller number from the larger number(Eg.54321- 12345)"
printfn "\t\t\tPress enter to continue..."
System.Console.ReadLine()|>ignore
System.Console.Clear()

printfn "\t\t\t Add 10000 to the difference"
printfn "\t\t\t Press enter to continue..."
System.Console.ReadLine()|>ignore
System.Console.Clear()

printfn "\t\t\tVisualize the sum while I try to read your mind."
printfn "\t\t\tPress enter to continue..."
System.Console.ReadLine()|>ignore
System.Console.Clear()

printfn "\t\t\tThe sum is…"
printfn "\t\t\tPress enter to continue..."
System.Console.ReadLine()|>ignore
System.Console.Clear()

printfn "\t\t\tThe sum is…"
printfn "\t\t\tPress enter to continue..."
System.Console.ReadLine()|>ignore
System.Console.Clear()

printfn "\t\t\tThe sum is…"
printfn "\t\t\tPress enter to continue..."
System.Console.ReadLine()|>ignore
System.Console.Clear()

printfn "\t\t\t51976"