need help

Apr 22, 2012 at 8:14am
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
Apr 22, 2012 at 8:27am
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.
Apr 22, 2012 at 8:42am
ya i know know but i need to write the code .
Apr 22, 2012 at 8:49am
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++?
Apr 22, 2012 at 8:51am
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;
Apr 22, 2012 at 10:04am
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 Apr 22, 2012 at 10:09am
Apr 22, 2012 at 10:11am
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.
Apr 22, 2012 at 10:12am
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.
Apr 22, 2012 at 10:15am
I didn't think about that. andrinirina shows one possible work around.
Apr 22, 2012 at 1:01pm
thanks to u all am really glad to meet u.
best regards
Topic archived. No new replies allowed.