Project Euler Question

This is a discussion on Project Euler Question within the C++ Programming forums, part of the General Programming Boards category; Im doing problem five on Project Euler. Basically, your supposed to find the smallest number that is evenly divided by ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    5

    Project Euler Question

    Im doing problem five on Project Euler. Basically, your supposed to find the smallest number that is evenly divided by the numbers from 1-20. heres my code, its just outputting 21, the condition on my loop.
    Code:
    #include <iostream>
    using namespace std;
    bool Divisible(int num, int divisor);
    int main()
    {
    	int end;
    	int i = 3;
    	int I = 2;
    	while (!Divisible(i,I))
    	{
    		i++;
    		I = 2;
    		do
    		{
    			Divisible(i, I);
    			if (!Divisible)
    				I = 21;
    			else
    				I++;
    		}while(I <= 20);
    			end = i;
    	}
    	cout<<end;
    }
    
    bool Divisible(int num,int divisor)
    {
    	if (num % divisor == 0)
    		return true;
    	else
    		return false;
    }

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    A number divisible by 1-20 WILL be much greater than 20.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    Your code doesn't make much sense either... review your C++. Especially the section on functions.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    5
    to the first commenter, im aware of that, thats the problem. and to the second person, it makes sense to me, could you refrence something specifically.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    They are the same person btw, as am I .

    could you refrence something specifically
    Code:
    if (!Divisible)
    A function call must have brackets, with the right number of arguments.

    What you are doing now is taking the address of the function, and evaluate that, which is most likely going to evaluate to true all the time, since it's probably not 0.

    Sidenote:
    Code:
    bool Divisible(int num,int divisor)
    {
    	if (num % divisor == 0)
    		return true;
    	else
    		return false;
    }
    is more conventionally written
    Code:
    bool Divisible(int num,int divisor)
    {
    	return num % divisor == 0;
    }

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    5
    diddnt look at the names, i just saw the seperate posts. I have fixed the first thing and it still evaluates to the same thing. Sorry if i seemed angry, but i felt insulted.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    Sorry if i seemed angry, but i felt insulted.
    It's okay, I do, too.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open-source Game Project
    By Glorfindel in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-24-2009, 01:12 AM
  2. Project Euler Solved but want help improving the code Newbie
    By whiterebbit in forum C++ Programming
    Replies: 4
    Last Post: 12-09-2008, 06:00 AM
  3. MSVC project question
    By l2u in forum Windows Programming
    Replies: 2
    Last Post: 03-28-2007, 10:45 AM
  4. application project
    By featherflutter in forum C++ Programming
    Replies: 2
    Last Post: 06-26-2004, 11:12 AM
  5. Please, suggest a project .
    By Dragon227Slayer in forum C# Programming
    Replies: 1
    Last Post: 06-12-2004, 11:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21