First of all, change your main() line to be int main()
The problem that you are having is that the program opens, does what it's supposed to do, and then closes. At the end of the program, right above the return 0 line, try entering:
char x;
cin >> x;
What that will do is prompt for a character to be input right before the program closes. Therefore, the program won't automatically close until it gets user input.
cscgal
The Queen of DaniWeb
19,422 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
I tried the char x; suggestion, but it still doesn't work :( . When I tried typing in "cin >> x;", I got an error saying that 'cin' is undeclared.
Dave's suggestion to look into the FAQ didn't work either. The faq says to type
system("PAUSE");
before the return 0 line, but I get an error that says:
implicit declaration of function `int printf(...)'
Uh, try reading it again and note the differences from what you have.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Since you are writing a C program use getchar() to wait.
// you can also use just #include <iostream>
// this works in DevCpp because iostream chain-includes down
// to sdtio.h (not recommended for portable code)
#include <stdio.h>
int main()
{
printf("Hello, world!\n");
getchar(); // wait
return 0;
}
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
u can use getch() at the end of the code for the screen to be still till u press any key.Or else u can use alt+F5 key to see the output window.
harshchandra
Junior Poster in Training
68 posts since Nov 2004
Reputation Points: 7
Solved Threads: 1