need help

hi am just a newbie in c++ and i got this assignment, i dont know what to do am just freaking ma self out. here is the question .
"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."
help me write out the code. thanks
You can split the problem in 2 problems.
1. Find the sum of all the multiples of 3 below 1000.
2. Find the sum of all the multiples of 5 below 1000.

Then you just need to add the two sums to get the sum you are looking for.
ya i know know but i need to write the code .
We can't do your homework, ozone. We're all glad to "help", not to do someone else's job.

First, let me ask you those questions:

1- Do you have a compiler?
2- Do you have an IDE?
3- if not, what operating system are you using?
4- What do you know in C++?
int ret=0:

// multiples of 3
for (int i=1; 3*i<1000; i++)
ret+= 3*i;

// multiples of 5
for (int i=1; 5*i<1000; i++)
ret+= 5*i;

// substraction of multiples of 15=3*5 counted twice
for (int i=1; 15*i<1000; i++)
ret-= 15*i;

return ret;
yeah i have a visual studio and a code block. am just a newbie trying to know programming, i am reading c++ tutorial on this site and some video tutorials too. my o.s is win 7 ultimate. i took the assignment from project euler
Last edited on
there's no need for you to rush it, it seems like you're trying to do something beyond your skills, just stick with what you know for a few days, practice it really often until you actually Know it, and than move on to the next Just a little more advanced lessons,and do the same routine again.

Ps. Sorry for off-topic.
You can split the problem in 2 problems.
1. Find the sum of all the multiples of 3 below 1000.
2. Find the sum of all the multiples of 5 below 1000.

Then you just need to add the two sums to get the sum you are looking for.


Except that the set of multiples of 3 contains some multiples of 5 and vice versa.
I didn't think about that. andrinirina shows one possible work around.
thanks to u all am really glad to meet u.
best regards
Topic archived. No new replies allowed.