0

I have a question that i am having difficulty with. The question is to write a function that creates the following pattern given the height(number of rows)which must be even. Please help!

*
***
*****
*******
*********
*********
*******
*****
***
*

Here is the code i have so far

#include <iostream>
using namespace std;

int main ()
{
    int limit;
    int row;

    //Read limit
    cout << "\nEnter an even number:";
    cin >> limit;

    for (int row = 1; row <= limit; row++)
    {
        for (int col = 1; col <= row ; col++)
        cout << '*';
        cout << endl;
        }

    for (int row = 1; row <= limit; row++)
    {
        for (int col = row; col <= limit ; col++)
        cout << '*';
        cout << endl;
        }



    return 0;
}

Edited by pyTony: fixed formating

3
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by SpS
0

See this

#include <iostream>
using namespace std;

void CreatePattern(int);

int main ()
{
int limit;
//Read limit
cout << "\nEnter an even number:";
cin >> limit;
CreatePattern(limit);

return 0;
}

void CreatePattern(int limit)
{

for (int row = 1; row <= limit; row++)
{
for (int col = 1; col <= row ; col++)
cout << '*';
cout << endl;
}

for ( row = 1; row <= limit; row++)
{
for (int col = row; col <= limit ; col++)
cout << '*';
cout << endl;
}

}

But your program doesn't do what you want to achieve.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.