I have an assignment requiring a program that creates a parallelogram of a specific size and makeup. I need to use at least one for loop and one while or do/while loop. So far, I've created a program that does this:
Enter the symbol to use to draw your parallelogram:
#
Enter the number of symbols to use for each side:
5
#
##
###
####
#####
####
###
##
#
Great, but not a parallelogram. It should do this:
#
##
###
####
#####
#####
#####
#####
#####
_####
__###
___##
____#
Ignore the underscores- I was just using them to create spaces.
I think I need to create a while or do/while loop that says, "Once you've gotten to the specified number (in the above case, 5), print that row 5 times." Then I need to create another for loop that says, "Once you've done that while or do/while loop, start subtracting characters from the left side until you get back to one."
Can someone give me an idea of how to do this or even if this idea is a good one? My current code is below. The //while (row=length) bit is my started attempt at a while, which is why I have it as a comment right now.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <cstdlib>
using namespace std;
int main () {
int length;
char symb;
cout <<"Enter the symbol to use to draw your parallelogram: "<< endl;
cin >> symb;
cout <<"Enter the number of symbols to use for each side: "<< endl;
cin >> length;
int row, col;
for (row=0; row<=length; row++) //Up and over row
{
for (col=0; col<=row; col++) //Up and over column
cout << symb;
cout << endl;
}
//while (row=length)
//{
for (row=length; row>=1; row--) //Down and over row
{
for (col=row; col>=1; col--) //Down and over column
cout << symb;
cout << endl;
}
}
|