Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/87827-solved-c-programming-question/
Share on other sites

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.

#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?

#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

Perfect.  ;D

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.