I'm not sure what you're trying to do with 4 "i" variables. Also, you didn't explain what you mean by "leaves" width. Ignoring those parts, it might be easier for you to figure out how to just do "45-45-90" triangle, meaning the height and width are the same.
Here's the simplest way (not using recursion) to do that:
1 2 3 4 5 6 7 8 9 10 11 12
|
int main()
{
const int WIDTH = 5;
for (int i = 1; i <= WIDTH; i++)
{
for (int j = 1; j <= i; j++)
{
std::cout << "*";
}
std::cout << std::endl;
}
}
|
Every inner loop, it prints asterisks up to what the number of the outer loop is, and every outer loop, it prints a newline, one for each row needed.
The problem with having an independent height and width is that the increase in stars each time will have to be calculated by the slope of the triangle. For example, in the above code, a 45-45-90 triangle's hypotenuse would have a slope of 1, it prints +1 asterisk for every +1 row.
But if the width was 2x the height, the slope of the triangle would be 1/2, and it would need to print out +2 asterisks each row to account for this. So, somewhere in your code, you'd need to calculate the slope (rise/run, height/width) and then use that to calculate how many more asterisks you need to bring for each row so that the final row will have the right amount printed... this could be hard because you're only dealing with integers, without thinking about code, what would a triangle with height 10, width 4 look like?