how to create asterik star like this


> with 10 Asterik star (*)

Clinton Portis commented: Excellent well formed question on a complex topic. +5

Recommended Answers

All 7 Replies

cout << "**********";
cout << "**********";

i mean like symbol (>)

cout<<"*"<<endl;
cout<<"   *"<<endl;
cout<<"    *"<<endl;
cout<<"  *"<<endl;
cout<<"*"<<endl;

I've wrote a function for this. Pass the number of lines for the function and then it will print a symbol like that.

void printAster(int noOfLines)
{
    int half=noOfLines/2;

    for (int i = 0; i < half; i++) // This for loop print the top half i.e. (\) part of (>)
    {
        for (int j = i; j > 0; j--)
            cout << " "; // the number of spaces for a line
        cout << "*" << endl; // the asterix symbol at the end of the line
    }

    for (int i = 0; i < half; i++) // This for loop print the down half i.e. (/) part of (>)
    {
        for (int j = i; j < half; j++)
            cout << " "; // the number of spaces for a line
        cout << "*" << endl; // the asterix symbol at the end of the line
    }
    cout <<"*"<<endl; // The last star
}

Note that if you pass a value like 2, there should be at least 3 lines to make a symbol like that. In other words consider the following codes.

cout<<"*"<<endl;
cout<<" *"<<end

and

cout<<"*"<<endl;
cout<<" *"<<endl;
cout<<"*"<<endl;

So you see my point?

I've wrote a function for this.

How nice. Did you read this? I guess not. :icon_wink:

sorry. That was my first post. I wrote that because firstPerson just used cout statements. Thought it will be cool if there was function for this. :P. Anyway thnx for telling me that.

sorry. That was my first post. I wrote that because firstPerson just used cout statements. Thought it will be cool if there was function for this. :P. Anyway thnx for telling me that.

No problem. Just try to help people with small pieces of code and explanation instead of just handing them a complete solution :)

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.