- // Learn more about F# at http://fsharp.net
- open System
- //change the title to Crack the Safe
- System.Console.Title<-"Crack the Safe"
- //change the foreground color to green
- Console.ForegroundColor<-ConsoleColor.Green
- //dislay the game title screen
- printfn "\t\t\t Crack the Safe"
- printfn "\t\t\t Press enter to continue..."
- //waits for a keypress from the user
- System.Console.ReadLine()|>ignore
- //Game action sequence
- printfn "\t\t\t You have found a legendary treasure chest"
- printfn "\t\t\t believed to contain the rarest gem on Earth"
- printfn "\t\t\t Press enter to continue... "
- //waits for a keypress from the user
- System.Console.ReadLine()|>ignore
- printfn "\t\t\t this chest can be opened only by"
- printfn "\t\t\t entering a mysterious 4-digit key code"
- printfn "\t\t\t Press enter to continue..."
- //waits for a keypress from the user
- System.Console.ReadLine()|>ignore
- let random=new Random()
- let intkeycode=Convert.ToInt32(random.Next(1000,9999))
- printfn "\t\t\tEnter the keycode:"
- let intusercode= Convert.ToInt32(Console.ReadLine())
- //if usercode is equal to the computer generated code then
- if intusercode=intkeycode then
- //display a congratulatory message
- printfn "\t\t\Congrats You have opened the treasure chest."
- //otherwise
- else
- printfn "\t\t\tInvalid Code"
- printfn "\t\t\tPress enter to continue... "
- System.Console.ReadLine()|>ignore
- printfn "\t\t\tGame Over"
Visual F# 100 Examples: Example 11
Problem: Make a simple crack the treasure chest console application game.
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
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" intsumProblem: 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
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 " dblpowerlossProblem: 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
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
Subscribe to:
Posts (Atom)