Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts

    Netscape Simple C++ Loops

    I'm trying to get back to learning C++. I have a basic code here, and it works but the console application keeps exiting after the loop, how can I prevent the application from exiting?

    Code:
    #include <iostream>
    
    void main()
    {
    	int iNumber;
    	int iCounter = 0;
    
    	std::cout << "How many times to loop?" << std::endl;
    	std::cin >> iNumber;
    	if ((iNumber) && (iNumber < 10000))
    	{
    		do
    		{
    			std::cout << "Looped content" << std::endl;
    			iCounter = iCounter + 1;
    		} while (iCounter < iNumber);
    	} 
    
    }
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #2
    Regular Coder BWiz's Avatar
    Join Date
    Mar 2006
    Location
    Sol System
    Posts
    471
    Thanks
    7
    Thanked 21 Times in 21 Posts
    I assume you are running this under Windows? The console window is exiting because your program has finished running. If you want to view your output, you can one of the following things:

    1) Use the either getch() (conio.h) or cin.get() to pause operation
    2) Use system("pause") (don't remember exactly)
    3) Execute your program in a console window [Start>run>cmd>%path%to%file/file.exe] rather than launching through explorer

    Bwiz.

    EDIT: Just a side note, I would make your main() function return an int, since this status code is returned to the operating system detailing the exit status of your program.
    Last edited by BWiz; 04-13-2010 at 04:30 PM.
    BWiz :: Happy Coding!
    2006
    2007 2008 2009
    2010 2011
    Irrational numbers make no sense.

  • #3
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    Thanks worked nicely!
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •