473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

magic code....

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();

}
}
}
}

Sep 4 '07 #1
7 1896
On Sep 3, 8:20 pm, vinnie <centro.ga...@gmail.comwrote:
When i execute the code, just the time to insert any number, and then
the window disapper. why?

for (int amount = 0; amount >= number; amount++)
if number is positive, Show() does nothing. Flip your comparison?

Sep 4 '07 #2
On Sep 3, 9:03 pm, Mark Peters <mpeter...@gmail.comwrote:
>
for (int amount = 0; amount >= number; amount++)

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?

Sep 4 '07 #3
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...
"vinnie" wrote:
On Sep 3, 9:03 pm, Mark Peters <mpeter...@gmail.comwrote:
>for (int amount = 0; amount >= number; amount++)
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?

Sep 4 '07 #4
On Sep 3, 10:38 pm, ModelBuilder
<ModelBuil...@discussions.microsoft.comwrote:
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

Sep 4 '07 #5
In that case, you probably don't need the console.read inside the loop at all.

"vinnie" wrote:
On Sep 3, 10:38 pm, ModelBuilder
<ModelBuil...@discussions.microsoft.comwrote:
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

Sep 4 '07 #6
Replace Console.Read() with Console.ReadLine() and the window won't disappear
until you press the Enter key to signify the end of a line of input.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"vinnie" wrote:
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();

}
}
}
}

Sep 4 '07 #7
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

"vinnie" <ce**********@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
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();

}
}
}
}

Sep 4 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: winnerpl | last post by:
Hey guys I'm trying to get a magic square but I'm stuck with it printing out only 1's and 0's in random places. Hope you experts can can provide some input on what I'm doing wrong. #include...
19
by: youpak2000 | last post by:
Are MAGIC numbers always bad? Using magic numbers (constant numbers) in programs are generally considered a bad programming practice, and it's recommended that to define constants in single,...
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
10
by: Jon | last post by:
All, Yes, it's more of the famous 'what do I do about magic_quotes' questions. Anyways, here we go: I've been a PHP developer for about a year now, and have grown to detest magic_quotes for...
16
by: per9000 | last post by:
Hi, I recently started working a lot more in python than I have done in the past. And I discovered something that totally removed the pretty pink clouds of beautifulness that had surrounded my...
8
KoreyAusTex
by: KoreyAusTex | last post by:
I am pretty new at programming and need some feedback as to why this program is not working??? It was a pretty big undertaking for me but I can't seem to figure out what is wrong: import...
2
by: jyck91 | last post by:
i have done the magic square: #include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 13 main() { FILE *fp; int i, j, n, row, column;
4
by: inferi9 | last post by:
Hi, I am working in a program caals magic square and it must be done only with loops and user definied funcations,I will tell you about my code and where my problem, the main is only calls the other...
6
by: tinman77 | last post by:
Hello, I'm having a terrible time using the functions finfo_open and finfo_file. I'm using PHP 5 on IIS 5.1 and Windows XP. I have enabled php_mime_magic.dll and php_fileinfo.dll and also added...
9
by: Larry Hale | last post by:
I've heard tell of a Python binding for libmagic (file(1) *nixy command; see http://darwinsys.com/file/). Generally, has anybody built this and worked with it under Windows? The only thing I've...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.