Why am I getting garbage?

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;
 
P

pvdg42

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.
 
T

Tamas Demjen

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