0

Why does the read int gets / 2?

Hello, in my Program I wrote: https://code.sololearn.com/cqBhxt1BoCMv/?ref=app but always when I enter the int it gets divided by 2 , why?

24th Sep 2018, 9:47 PM
Tinec
Tinec - avatar
1 ответ
+ 5
You can't use Console.Read() to get a number, it only reads one character, use Console.ReadLine() wrapped in a TryParse accordingly with the numeric type to be used; int age = 0; int.TryParse(Console.ReadLine(), out age); You can then check if age == 0, which indicated the input was not a valid number. Hth, cmiiw
24th Sep 2018, 10:25 PM
Ipang