Hi guys, im confused with my program, actually im using borland c++ before and it compiles, but when i change my compiler to dev c++, my program compiles but when i run the program and the first question appears on the screen and when i input the value it shuts down automatically, and it would'nt print the other output that comes out before when i using borland C++..
can anyone help me on this...
thanks in advance'
Borland sneaks in some code that pauses the program prior to exit. (It's a non-standard behavior.)
To explicitly get that behavior in Dev-C++, mingw, g++, etc, add the following to the end of your program:
-
// .. remainder of your code in main()
-
-
system("pause");
-
return 0;
-
}
-
An alternative (which doesn't depend upon the system's pause command):
-
// ... remainder of your code in main()
-
-
cout << "Press any key to exit ... " << endl;
-
char c = getchar();
-
return 0;
-
}
-
Note that you'll need to include <cstdio> for the second method. -- Paul