#include <iostream>
usingnamespace std;
int main()
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int jump = 0;
while (a < 1000)
{
a += 3;
c = a;
d = c + d;
}
if (a >= 1000)
{
d = d - a;
}
while (b < 1000)
{
jump++;
if (jump == 2) { b += 5; jump = 0; }
b += 5;
c = b;
d = c + d;
}
if (b >= 1000)
{
d = d - b;
}
cout << d << endl;
system("Pause");
return 0;
}
it did accualy go over for example "while (a < 10) { a += 3}" would end up with a = 12 (because 9 is lower than ten so i adds 3 a forth time) so i had to put in that thing for saftey. But i want the multiples of 3 and 5 all the way up to 1000 and then add them together. But it seems my program is'nt doing the job also multiples of that are the same for example both 5 and 3 get 15 my program is'nt allowed cout both of them so i did that jump thing. I'm getting 233498 while the answear is 233168.
it's supposed to get the multiples of 5 and 3 for example istead of 1000 I'll use 10. 3,6,9 are the multiples of 3 to 10 and the multiples of 5 to 10 is well 5. then im supposed to add these numbers 3, 6, 9, 5, the sum is 23 that's what I'm but instead of having ten as the limit I'm supposed to do a program that count like that to 1000 and then summs it up. Sorry for explaining so bad my I'm not very good a cpp and english.
Just tried the code you sent me (cool now I know how to keep track thnx) The numbers it displayed seemed to be correct a is going up with 3's and c is just a copy to save the number in while i add it in d. So it seems as im just as confused as i was before.
Thnx that helped me a lot with learning on how to write programs :D. But now for the final issue. 5 goes to 10 and then 15, and 3 goest to 6, 9, 12 ,15. And the problem is I'm not allowed to add up the same numbers to "d" so i tried making the "jump" so it would just jump over one by adding another 5 so it goes 5, 10, 20 instead of 5, 10, 15. so that i dont add up the same numbers in d.
so if a number is a multiplication of 5 but it is at the same time dividable by 3 you don't want it to be added up again? Like 15, 30, 45 ets was already added when your first loop was doing it's thing?
Are you aware that there is a simple formula to work out the sum of integers? Google that :+) The entire code for this problem is about 10 lines, the heart of it is only 3 lines.
Realise with project Euler, brute force is not the way to go, often the numbers are too big or it takes too long - so one has to think of a clever way of solving the problem. One big clue, often, is to think of ways to reduce the size of the problem set in some way - the less there is to do, the easier & quicker it will be.