Browse Source

Made a little guessing game

master
Lachlan Jacob 5 years ago
parent
commit
b41dcd8784
3 changed files with 21 additions and 2 deletions
  1. 3
    0
      .gitignore
  2. 0
    2
      for-fun-and-profit/folding.fsx
  3. 18
    0
      training/guessing.fsx

+ 3
- 0
.gitignore View File

@@ -0,0 +1,3 @@

.fake
.ionide

+ 0
- 2
for-fun-and-profit/folding.fsx View File

@@ -22,7 +22,6 @@ let alternatingSum n =
printInt (alternatingSum 100)

// Now we can factor out the commonality and re-write these functions like so:

let iterAct ini act n =
[1..n] |> List.fold act ini

@@ -31,4 +30,3 @@ printInt (product2 10)

let sumOfOdds2 = iterAct 0 (fun x y -> if y % 2 = 0 then x else x + y)
printInt (sumOfOdds2 10)


+ 18
- 0
training/guessing.fsx View File

@@ -0,0 +1,18 @@
open System

let r = Random()
let secretNum = r.Next(1, 100)
printfn "Secret Num is between 1-100"
let mutable found = false
while (not found) do
printfn "Enter a guess:"
let guess_s = Console.ReadLine()
let guess = Convert.ToInt32(guess_s)
match guess with
| guess when secretNum = guess ->
printfn "You guessed correctly!"
found <- true
| guess when guess > secretNum ->
printfn "Lower"
| _ ->
printfn "Higher"

Loading…
Cancel
Save