Teen Programmers Unite  
 

 

Return to forum top

can't tell why my program won't run...

Posted by kittifox_itezano [send private reply] at August 31, 2001, 06:27:42 PM

I just started learning C++ w/ The Complete Idiot's Guide to C++, so if I sound a little green around the gills I am. :)

Anyways, here's my problem: I typed in everything that the book told me to for my first program. Here's the code:

#include <iostream.h>

main()
{
cout << "testing this out... ";
return(0);
}

I compiled it and it told me there were no errors.

So when I ran the program, the screen flashed up for a second and disappeared. I ran it again, and it did the same thing. The screen looked right, so I don't THINK I typed something in wrong...

I downloaded a C++ compiler called Dev-C++, might that have something to do with it?

thanks for putting up with a newbie's cry for help. if you can think of what I might be doing wrong please let me know. God bless and thanks again!

~Kitti

Posted by sphinX [send private reply] at August 31, 2001, 06:57:04 PM

well, if you're running from windows (which i guess you are), what you've just compiled is either a DOS program or a windows console program (depending on your compiler), and all it's doing is opening a window, printing "testing this out... " and then exiting, which in turn closes the window. if you want to see it before it closes, add something that waits for a key to be pressed before exiting (i leave that as an exercise for you to figure out), or just run your program from the command prompt --- ie goto start-run and run "command" (or "cmd" if you're in win2k/nt/xp), change to the directory your program is in (ie 'cd c:\"My Stuff"\"Ultra cool test program"\') and then run it by typing the name of your program.

Posted by matheo917 [send private reply] at August 31, 2001, 07:00:06 PM

you are probably running it under windows, there's nothing
wrong with it, the windows just simply closes too fast,
execute that program in the Ms-Dos mode...

matheo917


Posted by TheTutor [send private reply] at August 31, 2001, 07:34:54 PM

Try this:

int main()
{
cout << "hello world!" << endl;
system("PAUSE");
return 0;
}

Posted by gian [send private reply] at September 01, 2001, 12:11:29 AM

Or... if you're not into dos calls, try:

int main()
{
cout << "hello world!" << endl;
getchar();
return 0;
}

Posted by sphinX [send private reply] at September 03, 2001, 01:17:36 AM

gee guys...way to go telling him the answer :-))

Posted by CHollman82 [send private reply] at October 01, 2001, 10:18:54 PM

Posted by khanbaba44 [send private reply] at September 09, 2001, 10:15:49 AM

The Dev-C++ compiler sux. It shows results in dos.so i wont use it but if u really want to compile a program on it.then do the following:
1.compile the program and save it on the desktop
2.then send it to C:\ and then go to Ms-dos and run it from there.

Posted by sphinX [send private reply] at September 09, 2001, 09:58:44 PM

or you could just goto start-run-"command" and run it fom whatever directory you want :-)

Posted by buzgub [send private reply] at September 10, 2001, 01:16:59 AM

BTW, dev-c++ isn't a compiler. It's an IDE for mingw32.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.