Displaying Pattern

I'm trying to come up with a program that will display the following pattern with a loop:

+
++
+++
++++
+++++

I wrote something that works, but I feel like there should be an easier way but I cannot figure out how. Please point me to the right direction. Help is much appreciated. Here's what I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

#include <iostream>
using namespace std;

int main ( )
{
	// Grouping the rows of Pattern A into a single loop
	for (int A = 0; A < 1; A++)	
	{
		// Defining counter variable for the number of + displayed
		int plus;		
		
		//Setting the number of + displayed per row
		for (plus = 0; plus < 11; plus++) 
		{
			cout << "+";
			if (plus == 0)		// row 1
				break;
		}
		cout << endl;
		
		for (plus = 0; plus < 12; plus++) 
		{
			cout << "+";
			if (plus == 1)		// row 2
				break;
		}
		cout << endl;
		
		for (plus = 0; plus < 12; plus++) 
		{
			cout << "+";
			if (plus == 2)		// row 3
				break;
		}
		cout << endl;

		for (plus = 0; plus < 12; plus++) 
		{
			cout << "+";
			if (plus == 3)		// row 4
				break;
		}
		cout << endl;
		
		for (plus = 0; plus < 12; plus++) 
		{
			cout << "+";
			if (plus == 4)		// row 5
				break;
		}
		cout << endl;
		
	}
	return 0;
}


You could accomplish this with two for loops; one nested within another.
1
2
3
4
5
for() {
     for() {

     }
}

My Solution: http://codepad.org/RdlEJdJV
Last edited on
Thank you! Your solution is much better.
Topic archived. No new replies allowed.