Thats the code i have so far: 
int _tmain(int argc, _TCHAR* argv[])
{
for ( int i = 1; i <= 9; i++)
    {
        for ( int j = 1; j <= 15; j++) { cout << "*"; }
        cout << endl;
    }




    return 0;
}
 but can't figure out how to make this one :    
 Write a program to display the following pattern


                                        x x x x x
                                        x x x x x 
                                        x x x x x 
                              x x x x x x x x x x x x x x x
                              x x x x x x x x x x x x x x x
                              x x x x x x x x x x x x x x x
                                        x x x x x
                                        x x x x x 
                                        x x x x x 

You need your loop to contain two different sets of behaviour. One for when i is 1-3 and 7-9, and one for when it is 4-6.

You can't do all that in one loop. In the first loop, print 5 spaces then 5 stars. Then in a second loop print 15 stars. The third loop is the same as the first loop. This is assuming you are required to use loops to print the characters one at a time. You could do the whole thing without any loops at all, but that would defeat the purpose of the assignment.

I need to use if,else statement in the loops,can you give a hint how?

Find out whith an if-statement, which line of the loop you are in(check loop index) Print stars or spaces and stars accordingly.

Here's a hint at a simple way to print out multiple lines with different things using conditions. I didn't want to do the assignment for you--you have to figure out what to put in each for statement, but maybe this hint can help you see the basic structure you might be able to use.

for(){
        cout << endl;
        if(X == 0 || X == 1 || X == 2 || X == 6 || X == 7 || X == 8){
            for(){
                cout << " ";
            }
            for(){
                cout << "X";
            }
            for(){
                cout << " ";
            }
        }else{
            for(){
                cout << "X";
            }
        }
    }
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=15;j++)
        {
            if((i<=3 || i>=7) && (j<=5 || j>=11))
                cout<<" ";
            else
                cout<<"*";
        }
        cout<<endl;
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.