help

Im trying to make an system like this
Points are spaces
...X
..XXX
.XXXXX
..XXX
...X

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() 
{
	cout << "Enter the numer:";
	int a;
	cin >> a;
	cout << endl;
	for(int i = 1; i <= a; i++)
	{
		for(int j = 1; j <= i; j++)
		{
			string b = " ";
			
			cout << b;
		}
		for(int j = 1; j <= i; j++)
		{
			
			cout << "X";
		}
		cout << endl;
	}
	return 0;
}
Last edited on
So what is your question?

BTW, you're missing:
 
#include <string> 

Start with a function that prints character ch out n times:
1
2
3
4
5
void repeat(char ch, int n) {
    for (int i=0; i<n; ++i) {
        cout << ch;
    }
}

This will make your code a lot easier to write.

The trick to printing a diamond is to recognize that you need two loops. The first loop prints the top half. Then the second loops prints the bottom half.
Topic archived. No new replies allowed.