|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (9 bit)
Join Date: Jul 2001
Posts: 355
|
Help
I just started out playing around with C++ today.
Anyway after i compile the code and run it, the dos prompt comes up and shows it for only about 1-2 seconds, what do i do to make it stay longer? Hers my simple code #include #include int main() { cout << "My name is Nick" << endl; int myage = 15; cout << "My age is" << myage << endl; cout << "The date is" < } |
|
|
|
|
|
#2 |
|
Member (9 bit)
Join Date: Jul 2001
Posts: 355
|
Im using Dev-C++ 4 to do this
|
|
|
|
|
|
#3 |
|
Member (13 bit)
Join Date: Jul 2000
Location: Fullerton, CA
Posts: 7,030
|
Hi ironzombie99,
You need to ask for user input so that the program will pause and you can see the results. Try this for example: Code:
#include
__________________
"A witty saying proves nothing." - Voltaire |
|
|
|
|
|
#4 |
|
Member (9 bit)
Join Date: Jul 2001
Posts: 355
|
thanks ill try this out
|
|
|
|
|
|
#5 |
|
Member (9 bit)
|
Rather than clicking on the .exe to run it...run it from a DOS prompt instead. I had to do this when I was trying to learn C++. Basically...when the program runs...it shuts down the prompt when the program finishes. But if you run it from within the DOS prompt, it shouldn't shut it down.
|
|
|
|
|
|
#6 |
|
Member (7 bit)
Join Date: May 2000
Location: Atlanta, Georgia
Posts: 95
|
you need to break the screen
try adding either cin.get(1); or getch(); to your code. Like this:
#include #include int main() { cout << "My name is Nick" << endl; int myage = 15; cout << "My age is" << myage << endl; cout << "The date is" < cout << "11/17/01" < return 0; cin.get(1); } or #include #include int main() { cout << "My name is Nick" << endl; int myage = 15; cout << "My age is" << myage << endl; cout << "The date is" < cout << "11/17/01" < return 0; getch(); } that will pause the screen and require you to press enter. requesting an input, such as 'cin' will not stop the screen to allow you to view the final output. it will only allow you to read the output up until the 'cin' statement. if using cin, and cin.ignore();, you will have two screen stops. try this out if u want to load 'myage' manually: #include #include int main() { cout << "My name is Nick" << endl; cin >> myage; cout << "My age is" << myage << endl; cout << "The date is" < cout << "11/17/01" < return 0; cin.get(1); } the '1' in cin.get(), for sake of simplicity, ignores the enter key. hope this helps. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|