Why the output is not what I want to…
Here’s the code:
int num;
Console.WriteLine("Please input age: ");
num = Console.Read();
Console.WriteLine(num);
For example I input 5, the output is 53. It needs to be 5, what is happening on the code. Can somebody explain? Thank you.
Because Console.Read() returns the character code of the next character in the stream. The ASCII character code of ‘5’ is 53.
You need to read the whole line as a string
and then
Parse()it orTryParse()it.