Trouble creating a pattern

Hey,
I am trying to create a pattern and can only get the first half going. I have tried negatives, switching up the signs, and nothing worked yet for me. Using Dev C++. An example would be...

Enter the number of lines:
2

Enter the character:
a

a
aa

aa
a



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

int main ()
{
    int r,l,ll,rr,neg,num=0;//
    string output,c;
    cout << "\nEnter the amount of lines: "<<endl;
    cin >> num;
    while (num>=0)
    {  
    cout << "What character will make up the pattern: "<<endl;
    cin >>c;
    cout <<endl;
    cout <<endl;

    for (l=0;l<=num;l++)//counts number of lines
    {    
    cout <<endl;

      for (r=1;r<=l;r++)//counts number of characters. 
      {
        cout <<c;
      
      }
    }
    neg=num*-1;
    for (ll=0;ll<=num;ll++)//counts number of lines
    {    
    cout <<endl;

      for (rr=1;rr<=l;r--)//counts number of characters. 
      {
        cout <<c;
      
      }
    }
    cout << "\n\nEnter the amount of lines: "<<endl;
    cin >> num;
    }
    cout <<endl;

{
        if (num<0)
    {
    cout << "Bye"<<endl;
    system("PAUSE");
}
}}


Last edited on
Firstly, You should really use better variable names. Even on short pieces of code a variable name like ll becomes un-readable.

2nd. You seem to be over-complicating the 2nd bit.

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
#include <iostream>

using namespace std;

int main() {

  int nu = 0;

  cout << "Enter Number: ";
  cin >> nu;

  for (int i = 0; i < nu; ++i) {
    for (int j = 0; j <= i; ++j)
      cout << "A";
  cout << endl;
  }

  for (int i = 0; i < nu; ++i) {
    for (int j = nu; j > i; --j)
      cout << "A";
    cout << endl;
  }

  cout << "Bye"<<endl;
  system("PAUSE");
  return 0;
}
thanks, I now understand my problem.
Topic archived. No new replies allowed.