K so I need to find all multiples of 3 and 5 below 1000 and add them all up.
Unfortunately I'm kinda stuck in the adding part. heres what I've got by now:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
int main()
{
int you = 0;
int sum ;
while (sum<1000)
{
sum +=you+1;
if (sum % 5 == 0 || sum % 3 == 0)
cout <<sum;
}
system ("pause nul");
return 0;
}
What is the output of this code? Surely you can see that it is the multiples of 5 and 3 and not the sum of them. Why then is your variable called 'sum' ? Rename it. 'you' is never changed. It serves no purpose. Remove it.
Once you do that, have a variable 'sum' initialized to 0. Every time you print a multiple in this code, add it to 'sum' instead.