Hi, so the exercise I am supposed to do is :
"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."
So, the question is pretty simply, nothing hard to understand. Here is the function I did to get it :
#include <iostream>
#include <string>
using namespace std;
int calculate(int max)
{
int result = 0;
for(int i = 1; 5 * i < max ; i++)
{
result += (i * 5);
cout << (i * 5) << " + ";
}
for( int i = 1 ; 3 * i < max ; i++)
{
result += (i * 3);
cout << (i * 3) << " + ";
}
cout << 0;
return result;
}
int main()
{
cout <<" = " << calculate(1000);
cin.ignore();
cin.get();
}
The function does give me a result but when I put it in to the exercise box, it says it's a wrong answer and would redirect me again to the problem. I don't see why it doesn't work, it works completely fine for the 10 but it won't work for the 1000;
And also, the couts in the calculate function are completely secondary, they were just there to show me what is getting added, you can delete them all, it won't matter;
And sorry if the solution to this is easy, I am in my first week of C++ so I'm still quite noob-ish;
Thanks a lot for the answers in advance guys :)
Oh, and if you want the website to this and many other problems, just ask me :), I didn't think it was necessary to resolve this though.