Ninjakreborn Posted January 25, 2008 Share Posted January 25, 2008 Basic application #include <iostream> using namespace std; int main() { cout << "Enter your age: "; int age; cin >> age; if (age > 20) { cout << "You are still young! \n"; }else { cout << "You are not so young anymore! \n"; } } Problem * I write this app * I compile it * I run it. Basically what is happening is it prompts for the age. You enter the age, and it automatically closes out the application. It's not showing one of the text messages (based off of what age you are). What am I suppose to do to be able to make it "stop" at a specific line. For example if I write 15-50 pages of code that just initializes various variables, does some things to them, then outputs them to the screen it runs too fast. It open's the app, and then runs through them all lightning fast then closes down. What do I need to do to make it to where it run's the lines, but where I can read them, then close the app down as I choose. Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/ Share on other sites More sharing options...
Ninjakreborn Posted January 25, 2008 Author Share Posted January 25, 2008 Basically how do I make a C++ application stop, so I have to click x in the window to close it. Everything I try to create ends up being a quick running app. It *Opens * Runs * Closes lightning fast. Is there a way to write an interactive one, that doesn't close so fast. Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/#findComment-449303 Share on other sites More sharing options...
fert Posted January 26, 2008 Share Posted January 26, 2008 are you using windows? Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/#findComment-449532 Share on other sites More sharing options...
Ninjakreborn Posted January 26, 2008 Author Share Posted January 26, 2008 I am using windows vista home premium. Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/#findComment-449602 Share on other sites More sharing options...
laffin Posted January 26, 2008 Share Posted January 26, 2008 system("pause"); shud work Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/#findComment-449695 Share on other sites More sharing options...
fert Posted January 26, 2008 Share Posted January 26, 2008 or these would work for(;; cin.get(); Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/#findComment-450052 Share on other sites More sharing options...
Daniel0 Posted January 27, 2008 Share Posted January 27, 2008 Just run the program from the console. It's supposed to close immediately since it's supposed to return to the console. Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/#findComment-450446 Share on other sites More sharing options...
Ninjakreborn Posted January 27, 2008 Author Share Posted January 27, 2008 #include <iostream> using namespace std; int main() { cout << "Hello world!\n"; return 0; cin.get(); } #include <iostream> using namespace std; int main() { cout << "Hello world!\n"; return 0; system("pause"); } For some reason neither of those worked. It still jumped straight through. It displayed hello world (so fast the human eye can't see it), then existed out of the window. Any advice? @Daniel0 - You mean to compile it, then run to teh application directly. The editor I am using has a built in compiler, and allows you to run it "through" the editor (it has a menu option for compile, and a menu option for run. Is that what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/#findComment-450447 Share on other sites More sharing options...
laffin Posted January 27, 2008 Share Posted January 27, 2008 pause is supposed to be a program file (pause.exe) on windows. I guess Vista has removed this program. Some Nifty Command line utilities u can put these in yer program folder or in a folder that is in the path. Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/#findComment-450471 Share on other sites More sharing options...
Daniel0 Posted January 27, 2008 Share Posted January 27, 2008 #include <iostream> using namespace std; int main() { cout << "Hello world!\n"; return 0; cin.get(); } #include <iostream> using namespace std; int main() { cout << "Hello world!\n"; return 0; system("pause"); } For some reason neither of those worked. It still jumped straight through. It displayed hello world (so fast the human eye can't see it), then existed out of the window. Any advice? When you return the rest of the code block will be discarded, so you need to move the system() call or cin.get() up before return. @Daniel0 - You mean to compile it, then run to teh application directly. The editor I am using has a built in compiler, and allows you to run it "through" the editor (it has a menu option for compile, and a menu option for run. Is that what you mean? No, I mean using Start > Run > cmd Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/#findComment-450517 Share on other sites More sharing options...
Ninjakreborn Posted January 27, 2008 Author Share Posted January 27, 2008 Perfect. that should give me everything I need to advance further for awhile. I was frustrated because when I was writing test applications just to try and learn the language, It kept running so fast I couldn't even guarantee it worked. I had written some stuff to do calculations, tried to make a test calculater. Then I was trying to work on a basic interface. However I couldn't get past that one part with it. Now I should be able to write something decent and be able to use that to test it. Thanks for showing me that, and thanks for all of the advice. I really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/#findComment-450526 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.