Author Topic: Codeblocks only runs "Hello world  (Read 12431 times)

Offline martina1988

  • Single posting newcomer
  • *
  • Posts: 2
Codeblocks only runs "Hello world
« on: February 14, 2019, 05:35:23 pm »
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.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Codeblocks only runs "Hello world
« Reply #1 on: February 14, 2019, 05:47:58 pm »
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.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1562
Re: Codeblocks only runs "Hello world
« Reply #2 on: February 14, 2019, 05:57:05 pm »
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).

Offline martina1988

  • Single posting newcomer
  • *
  • Posts: 2
Re: Codeblocks only runs "Hello world
« Reply #3 on: February 15, 2019, 09:51:06 am »
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;
}

The program runs until the second cin, then the window suddenly closes. Why is this?
« Last Edit: February 15, 2019, 05:41:26 pm by martina1988 »

Offline rcttsoul

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Codeblocks only runs "Hello world
« Reply #4 on: March 01, 2019, 09:27:54 am »
if your using the Wizards Hello World! is put in the main by default, you to remove and/or edit it
Discord = Pryor#2941

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Codeblocks only runs "Hello world
« Reply #5 on: March 01, 2019, 09:42:49 am »
Quote
CodeBlocks now runs the different programs I open but it stops halfway through.
For example, I have this program:
i missed somehow your post...

Quote
The program runs until the second cin, then the window suddenly closes. Why is this?
Isn't this obvious? After the last cin your program does nothing but printing the result and then closing the application... You have to tell your program to stop until the user exits the program...
http://wiki.codeblocks.org/index.php/FAQ-Compiling_(general)#Q:_My_program_runs_in_codeblocks_but_if_i_start_it_from_the_outside_it_only_flashes_and_closes_immediately