That's how I made my code. The answer is 1963521375 when I ran the program though, not even close to how it's supposed to be. I can't think of a way to fix this, and when I change some things around, I get the exact same answer. I don't even know what's going on, can somebody help me please?
Here's the question:
Quote:
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.
I know, I know, I'm really bad at this
Sponsor Sponsor
Insectoid
Posted: Sat Mar 30, 2013 9:52 pm Post subject: RE:Project Euler Problem 1
What are the initial values of fibSum and total?
Panphobia
Posted: Sat Mar 30, 2013 10:46 pm Post subject: Re: Project Euler Problem 1
get rid of the
code:
if (total > 4000000)
total -= fibSum;
you don't need it, other than that, Insectoid is right, look at total and fibSum
Dreadnought
Posted: Sat Mar 30, 2013 11:45 pm Post subject: Re: Project Euler Problem 1
Panphobia wrote:
get rid of the
code:
if (total > 4000000)
total -= fibSum;
you don't need it
While it is true that this will cause a problem, an if statement similar to this one is needed. There's just one little mistake in the statement. (wrong identifier possibly?)
Panphobia
Posted: Sat Mar 30, 2013 11:57 pm Post subject: Re: Project Euler Problem 1
Dreadnought @ Sat Mar 30, 2013 11:45 pm wrote:
Panphobia wrote:
get rid of the
code:
if (total > 4000000)
total -= fibSum;
you don't need it
While it is true that this will cause a problem, an if statement similar to this one is needed. There's just one little mistake in the statement. (wrong identifier possibly?)
the question only puts a restriction on the maximum value of the fibonacci number you are allowed to add to the total, not the total itself, so this would work
Cancer Sol
Posted: Sun Mar 31, 2013 4:33 pm Post subject: Re: Project Euler Problem 1
Panphobia @ 3/30/2013, 11:57 pm wrote:
Dreadnought @ Sat Mar 30, 2013 11:45 pm wrote:
Panphobia wrote:
get rid of the
code:
if (total > 4000000)
total -= fibSum;
you don't need it
While it is true that this will cause a problem, an if statement similar to this one is needed. There's just one little mistake in the statement. (wrong identifier possibly?)
the question only puts a restriction on the maximum value of the fibonacci number you are allowed to add to the total, not the total itself, so this would work
Oh... I read the question a million times and I thought i meant the total xD
My friend made one in turing though, got the same answer as I did before I added the if statement at the end, and it was wrong still.
Cancer Sol
Posted: Sun Mar 31, 2013 6:49 pm Post subject: Re: Project Euler Problem 1
Still doesn't work :/
Panphobia
Posted: Sun Mar 31, 2013 9:12 pm Post subject: RE:Project Euler Problem 1
post your updated code
Sponsor Sponsor
Cancer Sol
Posted: Mon Apr 01, 2013 9:35 am Post subject: Re: RE:Project Euler Problem 1
edit: I just changed the if statement that checks if the content is even from fib.one to fib.sum; I have no idea why fib.one was there
edit 2: It's still wrong
nullptr
Posted: Mon Apr 01, 2013 9:44 am Post subject: Re: Project Euler Problem 1
Don't check if the total is greater than four million -- check if the current term is greater than four million.
Cancer Sol
Posted: Mon Apr 01, 2013 10:00 am Post subject: Re: Project Euler Problem 1
nullptr @ 4/1/2013, 9:44 am wrote:
Don't check if the total is greater than four million -- check if the current term is greater than four million.
When I changed the while-loop to check fib.two, I got the same answer still.
nullptr
Posted: Mon Apr 01, 2013 10:41 am Post subject: Re: Project Euler Problem 1
Cancer Sol @ Mon Apr 01, 2013 10:00 am wrote:
nullptr @ 4/1/2013, 9:44 am wrote:
Don't check if the total is greater than four million -- check if the current term is greater than four million.
When I changed the while-loop to check fib.two, I got the same answer still.
I just copy-pasted your code and it gives the right answer (with or without that change). Try entering it in again -- maybe you made a typo the first time?
Cancer Sol
Posted: Mon Apr 01, 2013 11:42 am Post subject: Re: Project Euler Problem 1
nullptr @ 4/1/2013, 10:41 am wrote:
Cancer Sol @ Mon Apr 01, 2013 10:00 am wrote:
nullptr @ 4/1/2013, 9:44 am wrote:
Don't check if the total is greater than four million -- check if the current term is greater than four million.
When I changed the while-loop to check fib.two, I got the same answer still.
I just copy-pasted your code and it gives the right answer (with or without that change). Try entering it in again -- maybe you made a typo the first time?
The first time I made the program for it, I had the answer you just got too, but every time I enter it, it's wrong.
Maybe I'm just bad at copying it over to projecteuler.net lol
nullptr
Posted: Mon Apr 01, 2013 11:52 am Post subject: Re: Project Euler Problem 1
Cancer Sol @ Mon Apr 01, 2013 11:42 am wrote:
nullptr @ 4/1/2013, 10:41 am wrote:
Cancer Sol @ Mon Apr 01, 2013 10:00 am wrote:
nullptr @ 4/1/2013, 9:44 am wrote:
Don't check if the total is greater than four million -- check if the current term is greater than four million.
When I changed the while-loop to check fib.two, I got the same answer still.
I just copy-pasted your code and it gives the right answer (with or without that change). Try entering it in again -- maybe you made a typo the first time?
The first time I made the program for it, I had the answer you just got too, but every time I enter it, it's wrong.
Maybe I'm just bad at copying it over to projecteuler.net lol
Are you getting 4613732 as your answer?
Cancer Sol
Posted: Mon Apr 01, 2013 12:00 pm Post subject: Re: Project Euler Problem 1
nullptr @ 4/1/2013, 11:52 am wrote:
Cancer Sol @ Mon Apr 01, 2013 11:42 am wrote:
nullptr @ 4/1/2013, 10:41 am wrote:
Cancer Sol @ Mon Apr 01, 2013 10:00 am wrote:
nullptr @ 4/1/2013, 9:44 am wrote:
Don't check if the total is greater than four million -- check if the current term is greater than four million.
When I changed the while-loop to check fib.two, I got the same answer still.
I just copy-pasted your code and it gives the right answer (with or without that change). Try entering it in again -- maybe you made a typo the first time?
The first time I made the program for it, I had the answer you just got too, but every time I enter it, it's wrong.
Maybe I'm just bad at copying it over to projecteuler.net lol
Are you getting 4613732 as your answer?
Yes, but projecteuler keeps saying it's incorrect
I'll just try a few more times again.