Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

C++ array of parallelograms

juleejulee Member Posts: 1
Hi I have an assignment for my programming class, which includes printing out two parallelograms.

[img=http://i55.tinypic.com/29osop4.png]

There are 9 *'s in the 6 lines.

This is what I have so far. For some reason, it only prints out 1 * in each line. We are supposed to use nested loops. If anyone can help, thanks in advance.

[hr]
#include
using namespace std;

int main()
{
int column;

for ( int line=1; line<=6; line++ )
{
for ( int column=1; column <=line; column++ )
{
cout << '*';
{
for (column=line; column<=9; column++)
{
cout<< ' ';
}
}
}
cout << endl;
}

return 0;
}

Comments

  • etkietki Member Posts: 5
    this should work, i did the first part, you should probably try the second part. make sure you comment the code appropriately, that way you will understand what i did. you could pass in the number of lines and columns as command line arguments (argc, argv) and try to get some extra credit. kind regards, david


    #include

    int main(int argc, char* argv[])
    {
    int lines = 6;
    int columns = 9;

    for (int i = 0; i < lines; i++)
    {
    for (int sp = 0; sp < i; sp++)
    {
    std::cout << ' ';
    }
    for (int j = 0; j < columns; j++)
    {
    std::cout << '*';
    }
    std::cout << std::endl;
    }
    return 0;
    }
Sign In or Register to comment.