Project Euler Problem #5 Solution in C++ Project Euler #5: Smallest multiple
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?&quot;

And I'm wondering if my code to solve this problem is good and if there are ways to make it better.
#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
int main(){
int smallestMultiple = 40;
int i = 10;

while (i&lt;20){
    if (smallestMultiple%i == 0){
        i++;
        continue;
    }
    else{
        i = 10;
        smallestMultiple += 20;
    }
    }
std::cout &lt;&lt; smallestMultiple;
}
Code Review
Despite its name, &quot;stdafx.h&quot; isn't a standard header.  It doesn't seem to be needed, as the code compiles and runs without it.
Your indentation is off - perhaps that's a result of how you inserted the code into the question?
The continue is redundant - there's no more code within the loop after the if/else, so it can be omitted.
The code assumes that a result will be found before int overflows.  Remember that INT_MAX may be as small as 32767; perhaps unsigned long may be a better choice, or one of the fixed-width types specified in &lt;cstdint&gt;, perhaps?
Your loop structure would be clearer if you separate out the test from incrementing smallest multiple.  That could look something like this (still using int as our type):
#include &lt;iostream&gt;
#include &lt;climits&gt;

static bool is_multiple_of_all(int n, int max)
{
    for (int i = 10;  i &lt;= max;  ++i) {
        if (n % i != 0) {
            return false;
        }
    }
    return true;
}


int main()
{
    const int target = 20;
    for (int candidate = 2 * target;
         candidate &lt;= INT_MAX - target;
         candidate += target)
    {
        if (is_multiple_of_all(candidate, target)) {
            std::cout &lt;&lt; candidate;
            return 0;
        }
    }
    // not found
    return 1;
}

Algorithm
Project Euler problems tend to exercise your mathematical reasoning.  You're expected to find better methods than brute force search to find the solution.  (Hint: think about prime factors).