User forums > Help

Codeblocks only runs "Hello world

(1/2) > >>

martina1988:
Hello, I have a problem with CodeBlocks. Whenever I try to run a program, it always launches the
"Hello World" one.
 Here are the steps I follow.
1. After Starting CodeBlockchs, I choose File>New>Project.
2. In the New from template window, I select Console Application.
3. I select C++ as the language l use.
4. I choose a Project title, I choose the file where I've written the program as Project
filename. I create the project in the directory where the aforementioned file is.
5. I click Next and then Finish.
6. The file I have chosen appears in Management>Projects, on the left of the screen. I select the file
and press Build, then Run.
I posted about my problem earlier this week, and I was asked to report what appears in the Error Log
after I've pressed Run and then Rebuild. However, my post was deleted because I had to use Code tags
to indent it and I didn't know how to. Can somebody please tell me how to use them, so I can find a solution
to the problem? Thank you.

BlueHazzard:
code tags are the # symbol in the new post editor... If you press it there will appear some tags in the editor and you can paste the log or the code in between the two tags. You can add this tags multiple times for multiple logs...

You describe the steps until you have created the project... What do you do next?
Do you alter the main.cpp file? Do you save it? does some error message appears? Do you do a rebuild? You have to press the yellow gear to start the compiling and not only the green arrow! The green arrow will only launch the program but not compile it.

Miguel Gimenez:
The step 4 is not correct. You should create a new project in an empty folder, and once it is created you must edit main.cpp so it contains your code.

You can also add your file to the project (once the wizard has ended) and remove main.cpp from the project.

To insert code tags you must use the button with a # under the "Font face" combobox. You can also type the tag.

Everything you enclose between (code) and (/code) will be considered code (use square brackets instead of parenthesis).

martina1988:
CodeBlocks now runs the different programs I open but it stops halfway through.
For example, I have this program:

--- Code: ---#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cout<<"Insert an integer value for variable a\n" ;
    cin>>a;
    cout<<"Insert an integer value for variable b\n" ;
    cin>>b;
int result;
        result = a + b;
    cout<<"Sum of a and b:"<<result<<"\n";
result = a - b;
cout<<"Difference of a and b:"<<result<<"\n";
return 0;
}

--- End code ---

The program runs until the second cin, then the window suddenly closes. Why is this?

rcttsoul:
if your using the Wizards Hello World! is put in the main by default, you to remove and/or edit it

Navigation

[0] Message Index

[#] Next page

Go to full version