Anonymous
Are you sure that b can be exactly 4 million with that sequence?
Luigi
well, it can't be exactly 4 millions
Anonymous
Do that until b is less than 4 million
Luigi
but the exercise tells to sum numbers till the actual number reaches 4 million
Luigi
oh okay
Anonymous
But print b after counting on it
Luigi
so i'll change the loop condition
Anonymous
What was the first one?
Anonymous
<=?
Anonymous
Show the exercise question xD
Luigi
4 millions
Anonymous
You're getting confused
Luigi
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
Luigi
oh wait, i need to do only even numbers
Luigi
well is not a problem, just have to put an if
Anonymous
Anonymous
Luigi
oh values don't have to exceed 4 millions
Luigi
is there a way to put a gap?
Anonymous
Print b after you define it
Anonymous
Try this way
Anonymous
b = b+a
Cout<<" "<<b;
Luigi
wait 1 moment
Luigi
wait
Luigi
so
Anonymous
So
Luigi
b+a instead a+b? xD
Luigi
isn't that the same?
Anonymous
It's literally the same thing
Anonymous
Luigi
well, so it's the same as before xD
Anonymous
You have to print b after doing b = a+b
Luigi
oh
Anonymous
Luigi
before a= b-a
Luigi
same thing as before, maybe i have to do 2 loops
Anonymous
Do this, the cout has to be the last statement
Anonymous
Of the loop
Luigi
while (b<=4000000) {
b=b+a;
cout<<" "<< b ;
a=b-a;
}
Luigi
this is my loop
Luigi
before it was "cout<<" "<< b ;" after a=b-a;
Anonymous
while (b<=4000000) {
b=b+a;
a=b-a;
cout<<" "<< b ;
}
Anonymous
try this
Luigi
but wait, i have to calculate only even numbers, let me see if something changes
Luigi
i did that before, still gets to 5.5 millions
Anonymous
both should be the same, though
Anonymous
Luigi
kk
Luigi
it's an if
but maybe with even numbers it stops to 4 millions, who knows ahah
Luigi
i knew it
Luigi
it stopped to 3.5 millions
Luigi
while (b<=4000000) {
b=b+a;
a=b-a;
if (b%2==0)
cout<<" "<< b ;
Luigi
that's it
Luigi
thank you a lot btw @CristopherCerasuoli
Anonymous
Luigi
ahah, well, u helped me
Anonymous
it's just that i haven't programmed for a lifetime, i'm probably younger than you
Luigi
i would have never done it lonely
Luigi
how old are u?
Anonymous
15 lol
Luigi
me2
Luigi
by the way, i'm learning c++ by "Project euler" website
Luigi
someone told me that it's good for learning c++
Anonymous
never heard about that
Luigi
there are a lot of maths problems, that u have to solve with c++ programming
Luigi
that's where i got those exercises
Luigi
now i have to find prime factors of a number, i'll ask you if i need some help ahah
Ariana
rip
Ariana
Just use yafu
Luigi
what's that?
Ariana
a program to factor numbers
Ariana
Just copy the source code and done
Luigi
nah ahah
Luigi
i want to make it by myself
Luigi
i'm doing those exercises just for learning c++
Luigi
ahah
Anonymous
I am like what is abstraction? What is encapsulation? inheritance is fine, but stucked at polymorphism