triangle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;

// Main Function
void main()
{
	int x;
	int y;

	cout << "This program will display a triangle using the + symbol.\n\n";

	for ( x = 1; x <= 7; x = x + 2 )
	{
		for ( y = 1; y < 7; y = y + 2)
		{
			cout << "+";
		}
		cout << endl;
	}
	_getch();
}


Im trying to get a triangle displayed like this.

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

but i cant seem to get that all i get is

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

can someone help me, any ideas?
@Reaper1

This will do it for you. You need two sets of loops, one to angle up, the other, down.

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
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;

// Main Function
void main()
{
	int x;
	int y;

	cout << "This program will display a triangle using the + symbol.\n\n";

	for ( x = 1; x <= 7; x = x + 2 )
	{
		for ( y = 0; y < x; y++)
		{
			cout << "+";
		}
		cout << endl;
	}
	for ( x = 5; x >0; x = x - 2 )
	{
		for ( y = x; y > 0; y--)
		{
			cout << "+";
		}
		cout << endl;
	}
	_getch();
}
ah ok. thank you, i see and understand now, thanks for the help, whitenite1
Topic archived. No new replies allowed.