Parallelogram Problem: Write a program that prints the outline of a parallelogra
ID: 3644491 • Letter: P
Question
Parallelogram Problem:Write a program that prints the outline of a parallelogram (in this case a rectangle), where the width of the parallelogram is twice the height. The program will accept to inputs from the console, one will be the height (as an integer) and the other will be a character (as a char) that will represent the border.
Extra Credit [10 points]: Submit a solution that has two or less total repetition statements (loops).
Standard Input
6
$
Standard Output
What is the height of you parallelogram?
What character do you want to print?
$$$$$$$$$$$$
$ $
$ $
$ $
$ $
$$$$$$$$$$$$
Standard Input
0
$
Standard Output
What is the height of you parallelogram?
What character do you want to print?
Standard Input
20
+
Standard Output
What is the height of you parallelogram?
What character do you want to print?
++++++++++++++++++++++++++++++++++++++++
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
++++++++++++++++++++++++++++++++++++++++
Standard Input
2
+
Standard Output
What is the height of you parallelogram?
What character do you want to print?
@@@@
@@@@
Standard Input
1
!
Standard Output
What is the height of you parallelogram?
What character do you want to print?
!!
Explanation / Answer
Please rate...
#include<iostream>
using namespace std;
int main()
{
int h; char b;
cout<<"What is the height of the parellelogram ";
cin>>h;
cout<<"What character do you want to print ";
cin>>b;
for (int i=1;i<=h;i++)
{
for(int j = 1; j<=2*h;j++)
{
if (j == 1 || j == 2*h)
{ cout<<b;}
else if(i == 1|| i == h)
{ cout<<b;}
else
{cout<<' ';}
}
cout<<endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.