beginner and loops

hey guys i just started programming, and am having a hard time trying to figure out loops and how they work in general.
they gave us this example:

What multiples are we adding? 5
The sum of multiples of 5 less than 100 are: 950

and the loop for it is

cout << "What multiples are we adding? ";
int multiple;
cin >> multiple;
int sum1 = 0;
for (int count = multiple; count < 100; count += multiple)
sum1 += count;

cout << "The sum of the multiples of "
<< multiple
ok now my first question is how do you get all the loop info from the problem? where did the sum1 come from? and then how do you know what to put in the loop with the limited info that you have?
if anyone could break that down to me step by step would be really helpful and appreciated, thanks guys
[899 byte] By [shooter23000] at [2007-11-20 11:31:23]
# 1 Re: beginner and loops
For learning how to write this kind of thing, it helps to try to write out the program in english first. Im sure that you would be able to do that, than you will have a reference to create a code from.

Ill try to break it down for you.

cout << "What multiples are we adding? ";
int multiple;
cin >> multiple;
int sum1 = 0;

I think you should get this part. It asks you to enter the multiple that it is checking, and then has you enter it. Also, sum1 is defined here as 0, which is where the code stores the sum of the multiples

for (int count = multiple; count < 100; count += multiple)
sum1 += count;

This is the tricky part. If you read this as english, it would be something like this. Start checking numbers, starting from the multiple entered, and up to 100. Check numbers that are multiples of the number entered, by adding that multiple to the counter every loop. If multiple was '5', it would loop through 5,10,15,20 ect. up to 100. Everytime time it loops, add this number to the sum variable. For the same example, sum1 would be 5,15,30,50 ect.

cout << "The sum of the multiples of "
<< multiple

This shows the answer, and im guessing you cut off the "cout << sum1"
bovinedragon at 2007-11-9 1:25:45 >