Publish c++ code?

Hi, I just started writing c++, and this is probably a stupid question, but how do I make my c++ code into a program? I use code::blocks ( http://www.codeblocks.org/ ) which includes a compiler, etc, and when I create a new project, it saves the project in a folder, and in that folder is another folder named "bin", and inside "bin" is an Application file that I thought was my program, but whenever I try to open it, it just closes again after I enter all of my digits to add (it's an addition calculator)! The program works perfectly if I "Build and Run" it in code::blocks. Help!

(Here is my code below, it's supposed to be a basic calculator)

*code starts here*

#include <iostream>
using namespace std;

int calculator()
{
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;

int output;

cout << "This program is an addtion calculator." << endl;
cout << "This program will not accept decimals." << endl;
cout << "The maximum number of digits that you can add is 8." << endl;
cout << "If you wish to add less digits than 8, after your desired" << endl;
cout << "numbers are plugged in, keep entering 0 for the remaining digits." << endl;

cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
cin >> f;
cin >> g;
cin >> h;

output = a + b + c + d + e + f + g + h;

cout << "The sum of those numbers is " << output << "." << endl;
}

int main()
{
calculator();

return 0;
}

I use Code::Blocks as well, and assuming you also installed the GCC compiler, everything should be mainly set up for you awhile. There is a Project menu and under there are a few options, you want to "Build" your project, then "Run" it, or there is even a "Build then Run" option which does both at once. And welcome to the forums and C++ programming.
Windows automatically closes the console when the program has finished executing, that's all.
Either stick to running console programs from the console or see the sticky.
Actually in code blocks you don't have that issue. It's smart and displays information about the length it took to run the code, and puts a pause at the end of it.
Yes, Code::Blocks does that, not the program. So the issue remains when not running the program from within C::B. Also, when you plan to publish a program or give it to someone, always use the Release build, not the Debug build.
Last edited on
@Volatile Pulse
I believe he is running the executable directly, not from within code::blocks. You need to open a terminal and execute the binary within it.
Not really, you test applications for yourself. If someone else wants to try it from a different IDE, they can choose an improper pause to use, and of you're running from the command prompt, then you have nothing to worry about. Now if I plan on sharing my program, I'll run my binary before handing it out to make sure it stays open, but I never have that issue. And again, if you run the program from the command prompt, you don't have that issue anyways.

So that makes your point invalid about just running it from the command prompt if you're telling them they need to use a pause either way. And the main issue is finding out if they can compile or not. Let them mess around with coding before getting into symantics about releasing and command prompt. Usually beginners like to have an all in one area, I love my IDEs and I know others love cmd but let new people figure out what's best for them and get input later when they're comfortable with the language.
And on a note relevant to the OP, you declared calculator() as int but don't return any values. If you don't plan on returning any values, you can just define void calculator().
All the replies were really really helpful, thank you so much :)

-Peter
Topic archived. No new replies allowed.