magic code....

V

vinnie

When i execute the code, just the time to insert any number, and then
the window disapper. why?

namespace retry
{
public class Program
{
public static void Main(string[] args)
{
decimal number = 0;
InsertNumber(ref number);
Console.Write(" Number to be considerd: " + number);
Console.Read();
Show(number);
}
public static void InsertNumber(ref decimal number)
{
number = InsertNumber(" Value ");
}
public static decimal InsertNumber(string answer)
{
Console.WriteLine(" Insert the value of " + answer);
string accept = Console.ReadLine();
decimal value = Convert.ToDecimal(accept);
return value;
}
public static void Show(decimal number)
{
for (int amount = 0; amount >= number; amount++)
{
number = (number + 1);
Console.WriteLine(number);
Console.Read();

}
}
}
}
 
V

vinnie

if number is positive, Show() does nothing. Flip your comparison?

i did, and it happens this: if for example i put 10, i get:
9
8

but then all stops. If i push again enter, i get the same:

7
6
and so on... why?
 
G

Guest

I believe you get two values written per loop, since your reading one byte
from the console (read, rather than readline). When you hit enter, this is
two bytes. Change it to a readline and you get one value at a time.

It's hard telling from the code what you really want to get however...
 
V

vinnie

I believe you get two values written per loop, since your reading one byte
from the console (read, rather than readline). When you hit enter, this is
two bytes. Change it to a readline and you get one value at a time.

It's hard telling from the code what you really want to get however...

What i wish to realize is this: that once i have inserted the number,
i see the list of the operation, something like this (let's say that
the number is 8):
7
6
5
4
3
2
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

When a console program ends the console is closed, this is what is
happening, put a ReadLine() if you want the cosole to stick around
 

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

Similar Threads


Top