it suppose to look like this
Trapezoid with height 4, base1 3 and base2 9
EEE
EEEEE
EEEEEEE
EEEEEEEEE
but nothing is happening this is my code

``````else if (letter =='Q' || letter =='q')
{
cin>>hei>>wei>>draw;
base = hei*2;

cout<<"Trapezoid with height "<<hei<<"base1 "<<wei<<"and base2 "<<base;
cout<<endl;
for(i=1;i<hei;i++)
{
cout<<" ";
}
for (j=1;j<0;j++)
{
cout<<draw;
}
cout<<endl;
}``````
2
Contributors
1
2
Views
7 Years
Discussion Span
Last Post by PathikRaval

I hope the code you showed is just a portion of your entire code

I wrote my version with a few comments. I did not change much.

``````//  else if (letter =='Q' || letter =='q') {
int hei, wei, base, diff;
// diff is suppose to calculate the number of extra 'draw' chars to put in per row;
// it is later used in the for loop.

char draw;

cin >> hei >> wei >> draw;

base = hei * 2;

diff = (wei - base) / (hei - 2);
// the diff would be top base - bottom base divided by the number of rows
// this finds how many extra 'draw' chars to put in for each row

cout<<"Trapezoid with height "<<hei<<"base1 "<<wei<<"and base2 "<<base << endl;

for (int i = 0; i < hei; i++)
{
int number_of_characters_to_write = (wei - (diff * i));
// number_of_characters_to_write is self-explanatory
for (int j = 0; j < number_of_characters_to_write; j++)
{
cout << draw;
}
cout << endl;
}
// }``````

Edited by PathikRaval: n/a