Quantcast

Maximum PC

It is currently Fri Oct 24, 2014 8:01 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Complete Beginner with Simple Question
PostPosted: Sat Dec 06, 2008 5:48 pm 
8086
8086

Joined: Thu Jun 12, 2008 1:41 pm
Posts: 37
Location: OH-IO
I have been googling this for the last 1/2 hour but can't seem to find a definitive answer. As I said I'm basically a complete beginner and I'm trying to run the most basic of programs (my first one :-) ) a Hello World Program. When i try and run it a window pops up for a split second with the Hello World text but I can not find out how to pause it at this window instead of it simply closing right away.


Top
  Profile  
 
 Post subject:
PostPosted: Sat Dec 06, 2008 6:58 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
What language? There are a lot of things you can do. Have you tried running the program from the command line?


Top
  Profile  
 
 Post subject:
PostPosted: Sat Dec 06, 2008 9:33 pm 
Little Foot
Little Foot
User avatar

Joined: Mon Jul 28, 2008 1:39 pm
Posts: 123
Well, in my experience, C++, Java, Visual Basic, and possibly others will exit immediately after the last statement has executed. This behavior in the Hello World program can cause you to think that the program is malfunctioning, but it is most likely not. To combat this behavior, at the end of your program, you can put whatever statement in that language that reads text into a variable. For instance, in Java:
Code:
new java.util.Scanner(System.in).nextLine();

Or C++ :
Code:
int x;
cin >> x;

Or visual basic:
Code:
Console.ReadLine()

Hope this helps.


Top
  Profile  
 
 Post subject:
PostPosted: Sat Dec 06, 2008 10:12 pm 
8086
8086

Joined: Thu Jun 12, 2008 1:41 pm
Posts: 37
Location: OH-IO
Sorry about that, it's in C++ and I was doing it in Bloodshed...I tried what you said Quertior and it didn't work but then I went and used the same thing in Microsofts Visual C++ and it worked fine. Any reason for it working in one and not the other?


Top
  Profile  
 
 Post subject: program exiting without pause
PostPosted: Sun Dec 07, 2008 12:04 am 
8086
8086
User avatar

Joined: Sat Dec 06, 2008 11:57 pm
Posts: 3
If you are using Windows, your problem is that the command window will close when the program exits. insert this into the bottom of your code, right above the return statement (assuming main() returns a value)...

// system command to pause execution
system("PAUSE");

That should solve your problem.


Top
  Profile  
 
 Post subject: Re: program exiting without pause
PostPosted: Sun Dec 07, 2008 11:36 am 
Little Foot
Little Foot
User avatar

Joined: Mon Jul 28, 2008 1:39 pm
Posts: 123
s7arscream wrote:
If you are using Windows, your problem is that the command window will close when the program exits. insert this into the bottom of your code, right above the return statement (assuming main() returns a value)...

// system command to pause execution
system("PAUSE");

That should solve your problem.


...And in order to use the system() function, you need to put at the top of your program:
Code:
#include "cstdlib.h"


Top
  Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 8:49 pm 
Little Foot
Little Foot

Joined: Sat Feb 11, 2006 11:04 am
Posts: 174
you have to put return 0; at the end of the program


Top
  Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2008 10:01 pm 
Little Foot
Little Foot
User avatar

Joined: Mon Jul 28, 2008 1:39 pm
Posts: 123
Actually any int will work, but 0 is the standard.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 11:24 am 
Monkey Federation (Top 10)*
Monkey Federation (Top 10)*
User avatar

Joined: Sun May 22, 2005 8:28 am
Posts: 3673
Location: The Blue Nowhere
xxmainframexpxx wrote:
you have to put return 0; at the end of the program


The return 0; is simply the return code for the program. If you execute notepad.exe and it does not fail you should get a return of 0, if there are errors the code will change and is useful for debugging.

The return code of 0 is a standard success, any other return code is specific to the application.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.