Why am I getting garbage?

  • Thread starter Thread starter Allen Maki
  • Start date Start date
A

Allen Maki

//Hi there,

//I need help.

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

//(garbage).

//Can anybody tell me what am I doing wrong? And how it can be corrected?



#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;
 
Allen Maki said:
//Hi there,

//I need help.

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

//(garbage).

//Can anybody tell me what am I doing wrong? And how it can be corrected?



#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;
Start with the fact that the Read method does not read from the screen. It
reads the next character in the input stream.
The default input device is the keyboard.

http://msdn2.microsoft.com/en-us/library/system.console.read.aspx

Check the example code in the article. It should lead you in the right
direction.
 
Back
Top