Nested "for" loops for counting up then down.

I was able to make a counter that goes up but what about down? Overall I want it to go like so....

1
12
123
1234
12345
12345
1234
123
12
1



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
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int row, col;
int size;
int mych;


int printch = 1;


cout << "Size of Shapes (>0) ";
cin >> size;

while (size<0)
	{	
		cout << "\nSize of Shapes (>0) ";
		cin >> size;
	}


cout << "Characters to use: ";
cin >> mych;



for(row = 1; row <= size; row++)
{
	 printch = mych;
	cout << "\n" << setw(8);

for(col = 1; col <=row; col++)
{
	cout << printch;
	printch++;
	
	
}

}


for(row = size ; row <= size; row++)
{
	 printch = mych;
	cout << "\n" << setw(8);

for(col = mych; col <=row; col++)
{
	
	cout << printch;
	printch++;
	
	
}

}
cout << "\n\n";

system ("pause");

return 0;
}


Im stumped on this question. Any help would be appreciated!
What about something like:

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



int main()
{

	int x=1;
	int maxWidth=5;
	vector<int> printChars (maxWidth);

	for (int i=0;i<maxWidth;i++)//fills vectors with characters to be printed
	{
		printChars[i]=i+1;
	}


	while (x!=0)
	{
		if(x>maxWidth)//this will not return true until maxWidth has been achieved
		{
			while(x!=0)//this while loop will print back down until width=0
			{
				for(int i=0;i<x-1;i++)
				{
					cout<<printChars[i];
				}
				cout<<"\n";
				x--;
			}
		}
		else//just counts up to print first half
		{
			for (int i=0;i<x-1;i++)
			{
				cout<<printChars[i];
			}
			cout<<"\n";
			x++;
		}
	}
	return 0;
}


After I wrote it I realized naming x as currentWidth might have made it a little easier to understand.
Last edited on
Topic archived. No new replies allowed.