Drawing a triangle?

I'm taking a class on C++ where we need to copy examples from a textbook, and despite copying an example exactly it is not working as intended. The program is supposed to use a nested function to draw a triangle using [] as its building blocks, but it only makes one of each instead of repeating them every line. Please excuse the excessive comments, my professor asks us to comment on each line to get full credit for the assignment.

[#include <iostream> //allows for display of inputs and outputs on screen

using namespace std; //allows the usage of standard namespace commands
/*
Program which creates a right triangle given a vertical side length
*/

void print_triangle(int side_length)
{
if (side_length < 1) { return; } //if statement which verifies that the triangle does not have a 0 or negative side length
print_triangle(side_length - 1); //runs the function for the triangle with one less side length to to continue the triangle
for (int i = 0; i < side_length; i++) //for loop which runs the which creates each row to a length one larger than the one before
{
cout << "[]"; //outputs the boxes that make up the triangle
}
cout << endl; //ends the line to start the next row of the triangle
}

int main() //sets the starting point for the main function
{
cout << "Enter the vertical side length: "; //prompts the user to input the vertical side length
int input; //initializes the integer input for the side length
cin >> input; //inputs the value that was input by the user
print_triangle(input); //runs the print triangle function given the input

system("pause"); //pauses the system to allow the display to stay on screen
return (0);
}]
Put the code you need help with here.
[/code]
It works correctly for me:
C:\Users\Michael\Programming\foo> a
Enter the vertical side length: 4
[]
[][]
[][][]
[][][][]
Press any key to continue . . .

C:\Users\Michael\Programming\foo> _

What is it that you are seeing?
Topic archived. No new replies allowed.