nested loop problem!

Hi guys, for most of you PROs out there might think that the question is quite lame but here it goes... i have to create a cross pattern in c++ that looks like this ...
1
2
3
4
5
6
7
8
9
10
11
  
    **    
    **    
    **    
    **    
**********
**********
    **    
    **    
    **    
    **

using nested loops and only 2 cout messages such as cout<<"*"; and cout<<" ";
Ive managed to reach to the point where i get a single line cross ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
using namespace std;

int main()
{
int x, y;
	for(x=-4; x<=4; x++)
	{
		for(y=-4; y<=4; y++)
			{
				if(x==0||y==0)
				{cout<<"*";}
				else 
				{cout<<" ";}
				
			}
		cout<<endl;
	}
system("pause");
return 0;
}

Then i realized i have to consider the shape as 4 zones and i managed to get this
1
2
3
4
5
6
7
8
9
10
         *
         *
         *
         *
         *
         *
         *
         *
         *
**********

by changing the if statement to
 
if(x==4||y==4)

i guess this is the way it should be but i cant get the mirror cout for the other 3 zones in order to get the desired result...any help will be appreciated! Thanks!
Last edited on
The code with the one line cross is very close. You only need to change line 11 to get a double cross. What kind of condition should x be given so that it is satisfied for two values?
closed account (3qX21hU5)
Like hamsterman said the original if(x==0||y==0) is very close just thinking about adding a some conditions.
Topic archived. No new replies allowed.