After trying this simple console input with 5, the result is shown as 53
printfn "Enter no. of blocks: "
let nBlock = System.Console.Read()
printfn "entered value is %O" nBlock
Tried it on the interactive, still getting wrong results. Any solutions please?
You should try something like:
printfn "Enter no. of blocks: "
let nBlock = System.Console.ReadLine() |> System.Int32.Parse
printfn "entered value is %d" nBlock
Explanation:
you code only reads one character - as Lee mentioned with this you will read a line (ending after you press return) and parse that string into a int.
Remark: maybe you will want to check for a number, you can do this with TryParse:
printfn "Enter no. of blocks: "
let nBlock =
match System.Console.ReadLine() |> System.Int32.TryParse with
| true, n -> n
| false, _ -> -1
printfn "entered value is %d" nBlock
Of course you will have to check for the error case (-1) or change it into a option or something.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With