943,518 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1921
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 7th, 2007
0

Program runs but not visible

Expand Post »
Hi all

I am totally new to C++ and I am using the Dev C++ compiler and getting the tutorial off
http://www.cplusplus.com/doc/tutoria...structure.html
I ran the first program (code below) and it compiled fine but when I run it a box appears then dissappears so quickly I dont have time to see what it is but by the black colour I assume its DOS, can anyone tell me why it is doing this please as I don't know if my program is working correctly and I tried the other examples and the same happens, am I doing something wrong is that why it dissappears so quickly?
C++ Syntax (Toggle Plain Text)
  1. / my first program in C++
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. cout << "Hello World!";
  9. return 0;
  10. }

Many thanks

HLA91
Similar Threads
Reputation Points: 7
Solved Threads: 2
Junior Poster
HLA91 is offline Offline
177 posts
since Oct 2006
Oct 7th, 2007
0

Re: Program runs but not visible

You need to put a cin.get(); before the return 0;

Also the black window is commonly referred to as ze console window
Last edited by iamthwee; Oct 7th, 2007 at 3:19 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Oct 7th, 2007
0

Re: Program runs but not visible

Ok thanks it works now but why didnt the tutorial tell me that, can you recommend a good tutorial for me?

Many thanks for quick reply

HLA91
Reputation Points: 7
Solved Threads: 2
Junior Poster
HLA91 is offline Offline
177 posts
since Oct 2006
Oct 7th, 2007
0

Re: Program runs but not visible

> why didnt the tutorial tell me that

Because it ain't got nowt to do with c++, or the semantics of the language anyway. It depends on whether your IDE (integrated development environment) already has a built-in option to pause the program for viewing.

Some don't, some do.

If you ran your program from the command prompt there would be no need for the cin.get();.

>a good tutorial for me
There are a few useful snippets at daniweb. Look there. But ultimately the best way to learn is to try your hand at a problem and post your queries here.
Last edited by iamthwee; Oct 7th, 2007 at 3:31 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Oct 15th, 2007
-1

Re: Program runs but not visible

I have come across another problem again, the code from another tutorial wont be visible
C++ Syntax (Toggle Plain Text)
  1. // How IF Works#include <iostream>using namespace std;int main(){ cout << "Enter your age: "; int age; cin >> age; if (age < 20) cout << "You are still young!\n"; else cout << "You are not so young anymore.\n"; }
I did try placing cin.get(); before the closing bracket but that didn't work and I also added return 0; incase that helped but nope. Also I cant execute the programs on my laptop running windows Me when I type IF.exe when im in the folder it says syntax error is there something different with the DOS? Many thanks HLA91
Reputation Points: 7
Solved Threads: 2
Junior Poster
HLA91 is offline Offline
177 posts
since Oct 2006
Oct 15th, 2007
0

Re: Program runs but not visible

Unbelievable. 75 posts and you still don't know how to format your code ! I certainly hope you do not plan to turn in that to your instructor.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,945 posts
since Aug 2005
Oct 16th, 2007
0

Re: Program runs but not visible

What do you mean I dont know how to format my code, if you mean placing it in my post I obviously can becasue I did it in the first post of this topic all you did was comress it which to me makes it harder to read. Also I wont be handing it to my instructor becasue this is a hobby not a school subject.
Reputation Points: 7
Solved Threads: 2
Junior Poster
HLA91 is offline Offline
177 posts
since Oct 2006
Oct 16th, 2007
0

Re: Program runs but not visible

Click to Expand / Collapse  Quote originally posted by HLA91 ...
all you did was comress it which to me makes it harder to read. .
Nope -- we didn't do that. In the future please hit the Preview button before posting so that you can see what it looks like.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,945 posts
since Aug 2005
Oct 16th, 2007
0

Re: Program runs but not visible

Because I'm such a sweet guy:
C++ Syntax (Toggle Plain Text)
  1. // How IF Works
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7. cout << "Enter your age: ";
  8. int age;
  9. cin >> age;
  10. if (age < 20)
  11. cout << "You are still young!\n";
  12. else
  13. cout << "You are not so young anymore.\n";
  14.  
  15. return 0; //Yes I did put in 'return 0' because it's bad
  16. //practice to leave it out and yada yada yada...
  17. }

But to help you I guess we will nead a bit more info, the code should execute properly as it is. The problem of 'not visible', is it still in the ide?
Reputation Points: 10
Solved Threads: 2
Newbie Poster
jansson is offline Offline
8 posts
since Oct 2007
Oct 16th, 2007
0

Re: Program runs but not visible

>//Yes I did put in 'return 0' because it's bad
>//practice to leave it out and yada yada yada...
You're not getting away with this one. Explain why it's a bad practice, please.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: User defined functions
Next Thread in C++ Forum Timeline: Determin the average of an array that generates 30 random numbers.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC