I have written a simple console app that writes the sum of even elements of fibonacci sequence lesser than an upper bound.
#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;
}
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).