Need help with Patterns

Hello, I must be having Alzheimer's or something because I just can't seem to remember how to display this program properly.. I am supposed to display a pattern like this:

Pattern A
+
++
+++
++++
+++++
+++++++

Pattern B
+++++
++++
+++
++
+

And I can't seem to do it. Here is what I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main()
{
	cout << " ________________________________________________ " << endl;
	cout << " Pattern A	\t Pattern B		       " << endl;
	cout << " ________________________________________________ " << endl;

	for(int row = 1; row <= 10; row++)
	{
		for(int star_1 = 1; star_1 <= 10; star_1++)
		{
			cout << ' +';
		}
		cout << endl;
	}
	
	return 0;
}


Right now this is for pattern A, if I get this part then I can easily do
pattern B
Last edited on
Well you have two problems that i can spot. cout << ' +'; that space before the + is a problem as you're trying to print it as a single character...I'm not even sure what that will do but it won't make much sense. Make it '+' without the space or if you really want the space print it as a string literal " +" in double quotes.

Now that you're printing the characters properly, you need to decrease the amount of + signs that you print each loop (change the star_1 loop). You currently loop from 1 to 10 10 times so that'll print this


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


I understand that the star_1 loop needs to be changed, but is it completely or one expression??
Nothing I'm trying seems to be working :/
Pattern A

Hint: First row has 1 star, second row has 2, and so on ... Thus: If you index rows as 1, 2, ..., K where K is some integer (in this example, 6), then Row N has N stars. (except for row 6. I think that's a typo).

Pattern B

Hint: First row has 5 stars, second row has 4, and so on down to 1. Thus: If you index the rows as K, K - 1, K - 2, ..., 1 where K is some integer (in this example, 5), then Row N has N stars.
Last edited on
Alright, so I partly got it. (Sorry for the late post) When following the hint shacknar gave, I accidently got the pattern for Pattern B instead. So I know what I need to do now, thanks for the help.
This is what I got:

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
#include <iostream>
using namespace std;

int main()
{
	cout << " _________________ " << endl;
	cout << " Pattern A		       " << endl;
	cout << " _________________ " << endl;

	for(int row = 1; row <= 10; row++)
	{
		for(int star_1 = 1; star_1 <= (0 + row); star_1++)
		{
			cout << '+';
		}
		cout << endl;
	}

	cout << "\n\n";
	cout << " ______________" << endl;
	cout << " Pattern B		" << endl;
	cout << " ______________" << endl;
	for(int row = 1; row <= 10; row++)
	{
		for(int star_1 = 1; star_1 <= (10 - row); star_1++)
		{
			cout << '+';
		}
		cout << endl;
	}

	return 0;
}
Topic archived. No new replies allowed.