Need help with Console

A

Allen Maki

//Hi there,

//I need help.

//If I run the program and entered 100 at the prompt, I will get 45.

//Which is a random number found in memory. Can anybody tell me what

//am I doing wrong?



#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

using namespace System::IO;

int _tmain()

{

//Read from Screen

Int32 K = Console::Read();

Console::Write(K);



return 0;

}
 
J

Jon Skeet [C# MVP]

Allen Maki said:
//I need help.

//If I run the program and entered 100 at the prompt, I will get 45.

//Which is a random number found in memory. Can anybody tell me what

//am I doing wrong?

I suspect you actually got 49 - in which case it's not a random number
at all. It's the digit '1' in Unicode.
Console.Read() returns a single character - it doesn't take a whole
string and parse it into an integer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top