Hello everyone this is my first post on the daniweb community.
Currently I am home sick with a nasty cold so I was trying to solve a programming problem on a wonderfull sight called Project Euler.

The problem is as follows:
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.

Based on this problem I wrote this piece of code, which returns the value 266,333:

#include <iostream>

using namespace std;

int main()
    int x = 0;

    for(int i = 0; i < 334; i++)
        x += 3 * i;
    for(int i = 0; i < 200; i++)
        x += 5 * i;
    cout << x << endl;
    return 0;

However, this answer is wrong and I can not find a problem with my code any suggestions?

Thanks for the help and sorry if my code is not written that well, or sloppy I have just started learning programming for my school robotics team.

7 Years
Discussion Span
Last Post by frogboy77

Thank you that makes a lot of sense know, plus it shouldn't be to hard to fix.


most basic code for this problem(not the best,can be done with pencil & paper )is

many better ways than this

p.s. am currently running a program for project euler(will take days) so i can access the forum for the problem and see how the clever people did it.
great site but very addictive

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.