Hi Everyone,

I am just starting out so I am sorry for this basic of a question.

I have developed the code below to run a very simple program, but, each time the program runs the console window comes up during the program run but closes itself automatically. It should provide me with the option to "Press any key to close" I need it to stay open so that i can see the output of the program.

I am using visual studio 2008, I created a new 32bit blank project that is a console application. I created a new source file that is a C++ (.cbb) program source file.

I have written:

/*Given length in inches, this program outputs the equovalent
length in feet and remaining inch(es). */

#include <iostream>

using namespace std;
int main ()
{
    int inches; //variable to store total inches
    inches = 100; //store 100 in the variable inches
    cout << inches << "inch(es = "; //output the value of inches
    cout << inches / 12 << "feet (foot) and "; //output maximum
    cout << inches % 12 << "inch(es)" << endl; //output

    return 0;
}

Any input is greatly appreciate!

Neil

There is all the time a trick you can use:

char c;
cout << "Press any key to close";
cin >> c;

Add this before return 0.

@CGS That fixed it! Thank You!

I like the method posted by Philippe.Lahaie.

You can also acheive this by running without debugging, ctrl + F5

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.