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

else if (letter =='Q' || letter =='q')
	      base = hei*2;
              cout<<"Trapezoid with height "<<hei<<"base1 "<<wei<<"and base2 "<<base;
		  cout<<" ";
	      for (j=1;j<0;j++)

Hello ladylady

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 5 Years Ago by PathikRaval: n/a

We do not solve homework problems for people, we give them clues to help them solve the problems themselves.
This article has been dead for over six months. Start a new discussion instead.