magic code....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vinnie

    #1

    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(re f number);
    Console.Write(" Number to be considerd: " + number);
    Console.Read();
    Show(number);
    }
    public static void InsertNumber(re f decimal number)
    {
    number = InsertNumber(" Value ");
    }
    public static decimal InsertNumber(st ring answer)
    {
    Console.WriteLi ne(" Insert the value of " + answer);
    string accept = Console.ReadLin e();
    decimal value = Convert.ToDecim al(accept);
    return value;
    }
    public static void Show(decimal number)
    {
    for (int amount = 0; amount >= number; amount++)
    {
    number = (number + 1);
    Console.WriteLi ne(number);
    Console.Read();

    }
    }
    }
    }

  • Mark Peters

    #2
    Re: magic code....

    On Sep 3, 8:20 pm, vinnie <centro.ga...@g mail.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?

    Comment

    • vinnie

      #3
      Re: magic code....

      On Sep 3, 9:03 pm, Mark Peters <mpeter...@gmai l.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?

      Comment

      • =?Utf-8?B?TW9kZWxCdWlsZGVy?=

        #4
        Re: magic code....

        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...@gmai l.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?
        >
        >

        Comment

        • vinnie

          #5
          Re: magic code....

          On Sep 3, 10:38 pm, ModelBuilder
          <ModelBuil...@d iscussions.micr osoft.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

          Comment

          • =?Utf-8?B?TW9kZWxCdWlsZGVy?=

            #6
            Re: magic code....

            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...@d iscussions.micr osoft.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
            >
            >

            Comment

            • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

              #7
              RE: magic code....

              Replace Console.Read() with Console.ReadLin e() 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(re f number);
              Console.Write(" Number to be considerd: " + number);
              Console.Read();
              Show(number);
              }
              public static void InsertNumber(re f decimal number)
              {
              number = InsertNumber(" Value ");
              }
              public static decimal InsertNumber(st ring answer)
              {
              Console.WriteLi ne(" Insert the value of " + answer);
              string accept = Console.ReadLin e();
              decimal value = Convert.ToDecim al(accept);
              return value;
              }
              public static void Show(decimal number)
              {
              for (int amount = 0; amount >= number; amount++)
              {
              number = (number + 1);
              Console.WriteLi ne(number);
              Console.Read();
              >
              }
              }
              }
              }
              >
              >

              Comment

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

                #8
                Re: magic code....

                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" <centro.gamma@g mail.comwrote in message
                news:1188865253 .538691.123530@ 57g2000hsv.goog legroups.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(re f number);
                Console.Write(" Number to be considerd: " + number);
                Console.Read();
                Show(number);
                }
                public static void InsertNumber(re f decimal number)
                {
                number = InsertNumber(" Value ");
                }
                public static decimal InsertNumber(st ring answer)
                {
                Console.WriteLi ne(" Insert the value of " + answer);
                string accept = Console.ReadLin e();
                decimal value = Convert.ToDecim al(accept);
                return value;
                }
                public static void Show(decimal number)
                {
                for (int amount = 0; amount >= number; amount++)
                {
                number = (number + 1);
                Console.WriteLi ne(number);
                Console.Read();
                >
                }
                }
                }
                }
                >

                Comment

                Working...