C++ newbie need quick pointers with loops.

hi all,
i'm trying to display a sequence of numbers in rows of five using the for loop and it should look like this:

The numbers between 5 and 100 that are divisible by 7 are:

7, 14, 21, 28, 35,

42, 49, 56, 63, 70,

77, 84, 91, 98,


but whatever I try i keep on getting this:


7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98,

I tried putting another loop inside my loop to limit each output to 5 numbers in each row but for some reason it doesn't work. what do I need to do?

You need to post your code, because the algorithm sounds right, its just the implementation must be wrong.
This isn't perfect but it works. There is still more formatting you could do if you wanted.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main () 
{
	int j,num = 0;

	for(int i = 1; i < 15; i++)
	{
		num = i * 7;
		cout << num << ", ";
		if (++j >= 5)
		{
			j = 0;
			cout << endl;
		}
		
	}

    
	return 0;
}


Output will look like
7, 14, 21, 28, 35,
42, 49, 56, 63, 70,
77, 84, 91, 98,

Thank you bluegray. after implementing your code my program works perfectly now. my error was using postfix increment rather than the prefix. they're so confusing. I don't have a clue how to use them in loops. but looks like i'll have to go learn them now. anywayz, thank you again for bailing out a noob, saved me a ton of time not doing trial and error.
Last edited on
Topic archived. No new replies allowed.