Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made this program on a .txt I converted to .bat. Whenever I try to run the program it opens and closes instantly. Here it is;

C++
#include <iostream>
int main()
using namespace std;{


int main ()
{
	
	int i;
	cout <<"Input orbital period in seconds: ";
	cin >> t;
	cout << "Orbital time= " << t;
	cout << "Input Object distance from sun in meters: ";
	(cin >> d;
	cout << "Orbital distance= " << d;
	
	g = (6.6 * 10^-11)

	m = (d^3 * (4 * 3.14159)^2) / (g * (t^2))

	cout << "Object mass= " << m;


}
Posted
Updated 27-Aug-15 12:45pm
v2
Comments
Mohibur Rashid 28-Aug-15 4:52am    
What compiler are you using? Read the answer below. All of them are correct. Plus also learn if you press Ctrl+F5 in Visual studio your program will not disappear.

Try putting a getchar() in there so the user has to hit a key to continue ... see reference[^]
 
Share this answer
 
After
Quote:
cout << "Object mass= " << m;


Put
cout << "Press enter to continue...\n" ;
string dummy; // Have not used C++ in a while use any data type that you enjoy.
// This variable does nothing. You need your console to wait for an input.
// Which acts like a 'Pause'
cint >> dummy;
 
Share this answer
 
Apart from what others have said, if you are using this in Windows OS (Visual Studio for example as an IDE) I would recommend that you use this Windows-only command.

C++
system("pause");


Other answers also work, but this is a single function to pause the application. Plus this will also do what Clark's code does, it will automatically show the message to continue.

Only downside is that it is not a cross-platform feature. It is Windows-only.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900