I'm trying to write a program to output a parallelogram. It's suppose to be of a size the user choses and with a symbol chosen by the user as well. I am able to get a triangle and know that the basic principle is to treat it as two separate parts with one upside down triangle (or at least that's a hint I was given).
#include <iostream>
usingnamespace std;
int main ()
{
int i,j,rows;
char symbol;
cout << "How long do you want each side to be? ";
cin >> rows;
cout << "Please enter the character you want it to be made of: ";
cin >> symbol;
for(i=1;i<=rows;++i)
{
for(j=1;j<=i;++j)
{
cout<< symbol;
}
cout<<"\n";
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int n;
char symbol;
cout << "This program will output a parallelogram." << endl;
cout << "How long do you want each side to be? ";
cin >> n;
cout << "Please enter the character you want it to be made of: ";
cin >> symbol;
for ( int i = 0 - n; i < n; i++ )
cout << string( (i+abs(i))/2, ' ' ) + string( n-abs(i), symbol ) + '\n';
return 0;
}
It outputs like so:
This program will output a parallelogram.
How long do you want each side to be? 6
Please enter the character you want it to be made of: @
@
@@
@@@
@@@@
@@@@@
@@@@@@
@@@@@
@@@@
@@@
@@
@