How do I do so the program dont automatically closes after its been run? Reply greatly appreciated
How do I do so the program dont automatically closes after its been run? Reply greatly appreciated
Simplest thing is to just put in something like
The program will then wait for you to enter something before exiting.Code:int a; cin >> a;
Ok, I tryed to make a little thing in dos modus
code:
#include <iostream.h>
#include <stdlib.h>
int main()
{
int age;
cout<<"Please write your age"<<endl;
cin >> age;
int loc;
cout<<"Please write where you live"<<endl;
cin >> loc;
cout<<"you are "<<age<<" years old, and you live in "<<loc<<endl;
int exit;
cin >> exit;
return 0;
}
It doesnt seem to work at this point, it close fast just like earlier, can you see why?
Well I can't see why it should be doing that, but you can put,
in before the return statement.Code:system ("pause");
I just tried your example (without system ("pause")) and it works fine.
I assume you realise that you are using an integer to hold the value of the user input in response to the question about where the user lives. If you actually want them to write the name of their town or something you should use a character string.
OK, couple of things here.
Firstly:
should be:Code:#include <iostream.h> #include <stdlib.h>
Second, you're asking for location as an integer, you should learn about the char type and about arrays.Code:#include <iostream> #include <cstdlib> using namespace std;
Lastly read the FAQ on how to pause your program.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
thankz all