Thread: Project Euler Question

1. 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. A number divisible by 1-20 WILL be much greater than 20.

3. Your code doesn't make much sense either... review your C++. Especially the section on functions.

4. 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. 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. 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. Sorry if i seemed angry, but i felt insulted.
It's okay, I do, too.

Popular pages Recent additions