Like Tree3Likes
  • 2 Post By Sebastiani
  • 1 Post By kmdv

Need ur lil time......2 wk in progrmming!

This is a discussion on Need ur lil time......2 wk in progrmming! within the C++ Programming forums, part of the General Programming Boards category; ( C++ ) Should print multiple of 2 infinite Code: #include<iostream.h> #include<conio.h> void main( ) { clrscr( ); int number=2; ...

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    4

    Unhappy Need ur lil time......2 wk in progrmming!

    ( C++ )
    Should print multiple of 2 infinite

    Code:
    #include<iostream.h>
    #include<conio.h>
      void main( )
    {
        clrscr( );
    
      int number=2;    //declaration
        while( number>=2 )
             {
       
       cout <<number <<" \n ";   //will print multiples of 2 in in columns 
            number *=2;
                       }
    getch();
                  }

    unfortunately this will be terminated by printing 32768 value

    need ur help/suggestions .

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,712
    What you want cannot be done. At some point, you will have to stop printing multiples of two. In your case, it stopped because number was doubled beyond the maximum value for int, and presumably this arithmetic overflow resulted in number having a negative value, thus terminating the loop.

    Even if you change number from being an int to be say, an arbitrary precision integer type, you still cannot print multiples of two indefinitely: there is a limit to your computer's memory and such, and even if there wasn't, I doubt that you are immortal.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by laserlight View Post
    there is a limit to your computer's memory and such, and even if there wasn't, I doubt that you are immortal.
    Hold on now, let's not be too presumptuous...
    Xodix and SirPrattlepod like this.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    Quote Originally Posted by Xodix View Post
    unfortunately this will be terminated by printing 32768 value
    [assumption]Plz drop that TurboCrap you're using for a compiler that's younger than me.[/assumption]
    Devoted my life to programming...

  5. #5
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by GReaper View Post
    [assumption]Plz drop that TurboCrap you're using for a compiler that's younger than me.[/assumption]
    How old is Turbo Crap?
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  6. #6
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Too old
    Sebastiani likes this.
    I never put signature, but I decided to make an exception.

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    2,745
    Depending on version, release dates start at around 1987.

    Jim

  8. #8
    Registered User
    Join Date
    Nov 2013
    Posts
    4
    Quote Originally Posted by manasij7479 View Post
    How old is Turbo Crap?
    The version i was using is 3.8.0.1....

  9. #9
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    Quote Originally Posted by Xodix View Post
    The version i was using is 3.8.0.1....
    Assumption wrong, still valid though!
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-17-2013, 11:32 PM
  2. Replies: 2
    Last Post: 04-17-2013, 12:25 AM
  3. [HELP] Code to Convert Army Time to Normal Time?
    By Kipper DeVera in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2011, 11:50 PM
  4. Replies: 7
    Last Post: 11-21-2009, 12:02 AM
  5. progrmming in C
    By zeetaQ53 in forum C++ Programming
    Replies: 18
    Last Post: 07-21-2009, 12:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21