User forums > Using Code::Blocks

console app in windows xp doesn't run properly

(1/2) > >>

itbhp:
I have written a simple console app that writes the sum of even elements of fibonacci sequence lesser than an upper bound.


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

using namespace std;

vector<int> lista_fibonacci(int upper_bound)
{
    vector<int> lista;
    lista.push_back(1);
    lista.push_back(1);
    int i=1;
    while (lista[i-1]+lista[i] < upper_bound)
    {
        lista.push_back(lista[i-1]+lista[i]);
        i++;
    }
    return lista;
}

int Sum_even(vector<int> lista)
{
    int sum = 0;
    for (int i=0; i<lista.size(); i++) if((lista[i]%2)==0) sum+=lista[i];
    return sum;
}

void stampa(const vector<int> lista)
{
 for(int i=0; i<lista.size();i++)
  cout << lista[i] << " ";
 cout << endl;
}

int main()
{
    vector<int> lista_fib;
    int upper_bound=40000;
    lista_fib=lista_fibonacci(upper_bound);
    cout<<endl<<"Valori della serie di Fibonacci minori di "<<upper_bound<<endl;
    stampa(lista_fib);
    cout<<endl<< "La somma dei valori pari della serie di Fibonacci minori di "<<upper_bound<<" e': " << Sum_even(lista_fib)<<endl;
    return 0;
}


--- End code ---

I didn't start a project in CodeBlocks but I created only a simple cpp file. It builds right but when I try to run it in CodeBlocks, it appears a command window with these lines:

Process returned 0 <0x0> execution time : 0.109 s
Press any key to continue.

Searching the forum I discovered that these lines are related with a file "cb_console_runner.exe" that CodeBlocks calls when it runs console app.

The problem is that launching program from command line window after compiling works fine but running it in codeblocks doesn't, that is: it doesn't show my program output but only those lines.

How can I fix this?

Thanks for help,
 Paolo

P.S.: I use Windows Xp Home Service Pack 3 and CodeBlocks 8.02 (codeblocks-8.02mingw-setup.exe).

odubtaig:
Did you specifically create a console application project? It doesn't read like you did. I've not had this problem with the same release.

itbhp:

--- Quote ---I didn't start a project in CodeBlocks but I created only a simple cpp file.

--- End quote ---

By the way even starting a console application project the problem remains.

Probably I wasn't clear: the error is that by clicking the "Run" button in Codeblocks  it appears a command window with these lines:

Process returned 0 <0x0> execution time : 0.109 s
Press any key to continue.

even if the file.exe exists and I get the right output in a different command window I opened.

Jenna:
Your file works fine for me.


Pleae turn on full commandline logging :"Settings -> Compiler and debugger... -> Global compiler settings -> Other settings(rightmost tab)" "Compiler logging" to "Full commandline" .

And the run it again and post the lines from the "Build log".

itbhp:
Nothing has changed.  :(

This is the build log.


--- Code: --- mingw32-g++.exe -march=pentium-m -Os -W -g    -c "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp" -o "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.o"
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp: In function `int Sum_even(std::vector<int, std::allocator<int> >)':
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp:24: warning: comparison between signed and unsigned integer expressions
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp: In function `void stampa(std::vector<int, std::allocator<int> >)':
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp:30: warning: comparison between signed and unsigned integer expressions
mingw32-g++.exe  -o "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe" "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.o"   
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 2 warnings
 
Checking for existence: C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe
Executing: C:\Programmi\CodeBlocks/cb_console_runner.exe "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe" (in C:\Documents and Settings\paolo\Documenti\My_sources\c++)
Process terminated with status 0 (0 minutes, 11 seconds)
 

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version