now, it isn't the actual solving of the problem itself, i already have my algorithm to solve it, however, i think there is a problem in my algorithms logic.
the question is as follows:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
[/quote]
and my c++ program to solve it is:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int answer = 0;
for (int number = 0; number < 1000; number++)
{
if ((number%3) || (number%5) == 0)
{
if ((number%3) && (number%5) == 0)
{
answer += 0;
}
else
{
answer += number;
}
}
}
cout << answer <<endl;
return 0;
}
when i change the run until clause in the for statement to 10 so i can check my working out against the correct solution however, it outputs 22 instead of 23, and i just can't figure out why this is.
any help at all would be much appreciated as i've looked at this problem from every which way and cannot see the error.