Created
June 11, 2016 08:25
-
-
Save esehara/e6677be34eee1b7b0a49806da9fa200c to your computer and use it in GitHub Desktop.
初めてのFSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let message ans user = | |
if (ans > user) then | |
"答えはもっと大きいよ" | |
elif (ans < user) then | |
"答えはもっと小さいよ" | |
else | |
"You won !" | |
let rec gameLogic ans time = | |
printf "Input > " | |
let user_input = Console.ReadLine() | |
if System.String.Equals(user_input, "") then | |
gameLogic ans time | |
else | |
let user_answer = System.Int32.Parse(user_input) | |
printfn "%s" (message ans user_answer) | |
if ans = user_answer then | |
printfn "%d回数で当てました" time | |
else | |
gameLogic ans (time + 1) | |
[<EntryPoint>] | |
let main argv = | |
printfn "*** 数当てゲーム ***" | |
let ans = System.Random().Next(1, 100) | |
gameLogic ans 0 | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment