help with problem

I started programming and i need help with this problem i do not know what is wrong with it.




/* 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.*/

#include <iostream>

using namespace std;

int main()
{
int num;// variable to test values
int sum = 0; //final sum value
int a = 0; // to use for increasing array element

int storage3 [1000];// to hold all of the values that work for 3
int storage5 [1000];//to hold all of the values that work for 5


//Loop to test for multiples of 3
for (num = 0; num < 1000; num++){

int rem3 = num % 3;

if (rem3 == 0) {
num = storage3 [a] ;
}
else{
storage3 [a] = 0;
}
a++;

}

//Loop to test for multiples of 5
for (num = 0; num < 1000; num++) {

int rem5 = num % 5;

if (rem5 == 0) {
num = storage5 [a];
}
else{
storage5 [a] = 0;
}
a++;
}


// loop to sum all numbers
for (int a = 0; a < 1000; a++) {
sum += (storage3 [a] + storage5 [a]);

}
cout<<sum;


}
Please use [code][/code] tags.

I think your assignments are reversed in the case where the number is in fact a multiple of 3 or 5.
they are supposed to be multiples of 5 or 3. the num variable tests all numbers 0 - 1000 to check.
I understand what you assignment is. Please see my suggestion.
see what i see is your assign is to just to list out the multiples of 5 and 3
why do yu need to check the no.s from 0-1000 just find the multiples of them
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main(int argc, const char * argv[])
{
    const int SIZE(1000);
    int numbers[SIZE] = {0};
    
    for (int n=3; n < SIZE; n+=3)
        numbers[n] = 1;
    for (int n = 5; n < SIZE; n+=5)
        numbers[n] = 1;
    for (int n = 1; n < SIZE; ++n)
        if (numbers[n])
            cout << n << endl;
   
    return 0;
}
Topic archived. No new replies allowed.