Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Project Euler Problem 1
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nullptr




PostPosted: Mon Apr 01, 2013 1:07 pm   Post subject: Re: Project Euler Problem 1

Cancer Sol @ Mon Apr 01, 2013 12:00 pm wrote:
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 Sad
I'll just try a few more times again.

Edit: Nvm, the answer I have is 4285822


That's really weird, it works on codepad: http://codepad.org/vqvwKwvs. It must be something on your computer or compiler.
Sponsor
Sponsor
Sponsor
sponsor
Cancer Sol




PostPosted: Tue Apr 02, 2013 12:56 am   Post subject: Re: Project Euler Problem 1

nullptr @ 4/1/2013, 1:07 pm wrote:
Cancer Sol @ Mon Apr 01, 2013 12:00 pm wrote:
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 Sad
I'll just try a few more times again.

Edit: Nvm, the answer I have is 4285822


That's really weird, it works on codepad: http://codepad.org/vqvwKwvs. It must be something on your computer or compiler.


I'll try it on compilr to see if it's fine on it. if it is, it might be my computer (actually, it's my mom's)
Insectoid




PostPosted: Tue Apr 02, 2013 6:45 am   Post subject: RE:Project Euler Problem 1

code:
fib.one=1, fib.two=1, fib.total=0;


There's something missing from this line.
Cancer Sol




PostPosted: Tue Apr 02, 2013 10:48 am   Post subject: Re: RE:Project Euler Problem 1

Insectoid @ 4/2/2013, 6:45 am wrote:
code:
fib.one=1, fib.two=1, fib.total=0;


There's something missing from this line.

Am I supposed to assign fib.sum its value already? I'm not sure what I'm missing still.
So do I do it like:
code:

fib.one=1, fib.two=1, fib.sum=fib.one + fib.two, fib.total=0;
Insectoid




PostPosted: Tue Apr 02, 2013 5:13 pm   Post subject: RE:Project Euler Problem 1

Woops, never mind. Thought you were adding to it instead of assigning it directly.
Cancer Sol




PostPosted: Thu Apr 04, 2013 3:45 pm   Post subject: Re: Project Euler Problem 1

Idk, I give up. Too hard lol xD
I'll do these questions another time.
The only one I could do is only the first question, so sad Crying or Very sad
Panphobia




PostPosted: Thu Apr 04, 2013 4:58 pm   Post subject: Re: Project Euler Problem 1

Ok I edited your code from when you first posted a while ago, and since you might be having problems with your compiler, try this, this gave me the correct answer 100%
c++:
#include <iostream>
using namespace std;

int main()
{
    int fib1=1, fib2=1, fibSum=0, total=0;
    while (fibSum < 4000000)
    {       
        if (fibSum % 2 == 0)
            total += fibSum;
        fibSum = fib1 + fib2;
        fib1 = fib2;
        fib2 = fibSum;
    }
    cout << total;
}
Cancer Sol




PostPosted: Fri Apr 05, 2013 1:17 am   Post subject: Re: Project Euler Problem 1

The answer is 4613732 right? Because when I entered it in the website, it still said it's wrong.
Sponsor
Sponsor
Sponsor
sponsor
nullptr




PostPosted: Fri Apr 05, 2013 7:21 am   Post subject: Re: Project Euler Problem 1

Cancer Sol @ Fri Apr 05, 2013 1:17 am wrote:
The answer is 4613732 right? Because when I entered it in the website, it still said it's wrong.


Yeah, it is 4613732. It even says so on the problem page once you've solved the problem, so I can't think what's giving you trouble.
Panphobia




PostPosted: Fri Apr 05, 2013 8:30 am   Post subject: RE:Project Euler Problem 1

Cancer maybe you have entered the security code wrong? Have you ever thought of that?
Cancer Sol




PostPosted: Fri Apr 05, 2013 4:17 pm   Post subject: Re: RE:Project Euler Problem 1

Panphobia @ 4/5/2013, 8:30 am wrote:
Cancer maybe you have entered the security code wrong? Have you ever thought of that?

Well here's what the second page says after I enter the answer:
Quote:
Sorry, but the answer you gave appears to be incorrect.

I don't think that's the wrong confirmation code :/
Panphobia




PostPosted: Fri Apr 05, 2013 4:43 pm   Post subject: RE:Project Euler Problem 1

definitely is the right answer

MOD Edit: Let's draw the line at helping with the code. We don't need to see the actual value.
Cancer Sol




PostPosted: Fri Apr 05, 2013 4:51 pm   Post subject: Re: RE:Project Euler Problem 1

Oh wait actually... I've been entering it for the wrong question, my bad xD
Thanks! I was entering it for question 3 the whole time, LOL.
That was why it didn't work the whole time...
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 28 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: