In need of assistance

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>
using namespace 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;
}

If any1 could help me, I'd appreciate it :)
Last edited on
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.
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
int main(){
   int sum=0;
   for(int i=0;i<1000;i++){
      if(i%3==0||i%5==0)sum+=i;
   };
   cout<<sum;
   cin.get();
   return 0;
};
ok thx people :) I did it. Also, if you want some problems to solve, go to www.projecteuler.net
Thx again!
Last edited on
Topic archived. No new replies allowed.