Do you think this program will find the multiples of 3 and 5 in 1000?

I just want to make sure this program does exactly as it was intended to do. I'm trying to find all the multiples of 3 and 5 from 1000 and add those numbers to an accumulator and print the result.

Is this how you find the multiples of 3 and 5 from 1000?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;


int main ()
{
    int total = 0;

for (int n = 3; n <= 1000; n++)
{
    if (n % 3 == 0)
        total += n;
    else if (n % 5 == 0)
        total += n;
    else
        total += 0;
}
    cout << total;

}
Last edited on
looks good, though line 16 and 17 are a waste.
Topic archived. No new replies allowed.