Loop within a loop

Hello, My homework assignment is to output the first 5 even numbers on 3 lines, similar to below:

2 4 6 8 10
2 4 6 8 10
2 4 6 8 10

I can print something on 3 lines and I can print 5 even numbers but I do not know how to combine them. This is what I have so far. Any help would be much appreciated.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #include <iostream>
using namespace std;
int main()
{
		int count;
		count = 2;
		while (count < 11)
		{
			cout << count << " ";
			count = count + 2;
		}
		cout << endl;
		
	system("PAUSE");
	return 0;
}
Last edited on
You say you can print something on 3 lines. Does it look like:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;
int main()
{
  int line = 0;
  while ( line < 3 )
  {
    cout << "something\n";

    ++line;
  }
  return 0;
}

The "something" is on line 8. It prints one line of text.

On your other program you have:
1
2
3
4
5
6
7
8
int count;
count = 2;
while (count < 11)
{
  cout << count << " ";
  count = count + 2;
}
cout << endl;

That prints one line of text.

What if you replace the cout << "something\n";?
So that would help me print 3 lines of text. But where you wrote "something," I think I am supposed to have the loop I wrote above. Thus the "loop in a loop" idea.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 #include <iostream>
using namespace std;
int main()
{
    for (int count = 0; count < 3; count++) {
    
	  for (int i = 2; i < 12; i+= 2) {
	   cout << i << " ";   
	  }
	
	cout << endl;
    }
		
	system("PAUSE");
	return 0;
}
Topic archived. No new replies allowed.