# Thread: Help with simple while program!!!!

1. ## Help with simple while program!!!!

The first part is I am trying to make this program look like this:

10 12 14 16 18 20
22 24 26 28 30 32
34 36 38 40

I am trying to do this with a while loop. I have to make each line only show 6 number per line. THe only thing I can't get it make the my interger, counter, add 2 to it each time and make 6 only on each line.

2. I take that back. I can get it to count by 2 but don't know how to make only 6 numbers show up per line.

3. Well, at least you have something. Show us what you have so far so we can suggest how to make it do what you want it to do.

4. Code:
```counter = 100;
do {
counter = counter + 2;
cout << " " << counter;
} while (counter <= 148);

return 0;
}```

5. This is the hint out teacher gave us But I don't understand how to: To help with printing only six numbers per line, you can setup a separate variable that gets incremented inside the loop once for each time through the loop. This second counter can keep track of the number of values displayed on the line. When it reaches 6, you can output a newline and set that variable back to 0.

7. Well, your teacher's hint is what I would have suggested.

You can test it out this way: write a program to print:
Code:
```1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18```
by using a loop to loop over the natural numbers (instead of hard coding the output).

8. well the problem is is that I don't know how to make only certain amout of numbers go one row.

9. Originally Posted by walkonwater
well the problem is is that I don't know how to make only certain amout of numbers go one row.
Notice that 6 is perfectly divisible by 6, as is 12 and 18. Use that to your advantage with operator % by printing a new line appropriately.

10. That is funny. I emailed my teacher and he told me to use the operator as well but I don't get how to use it. I knew 6 would pay a factor of course but I didn't undertand how to make the cout part of this to perform the 6-per-line.

11. But with the operator, I do not understand how to write that to make it only produce 6 per line.

12. Well, I do not want to give the whole game away, so here is the pseudocode for the algorithm:
Code:
```for i = 1 to i = 18
print i
if i is perfectly divisible by 6
print new line```

13. the integer "i" would be my counter right?

14. Yes, but of course you have to adapt this to your actual problem.

15. so would it look like this:

Code:
```for i = 1 to i = 18
cout << counter;
if counter % 6;
cout << endl;```
but I don't understand how to do the first for statement if the rest is correct.