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!


5 Years
Discussion Span
Last Post by Suzie999

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.


I like the method posted by Philippe.Lahaie.

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.