Hi im needing a wee bit of help creating a series of triangles that get bigger each time the user has to input the number of triangles they want. I have managed to get my code to produce one triange but i cant get the loop to run for the number of triangles. Any help would be great thanks guys
Code:
#include <iostream> // using the main library
using namespace std;
// Function declarations
char this_char () ;
int get_num_row () ;
void draw_tri ( char this_char, int num_row ) ;
int main ()
{
char this_char = '*' ;
//Get number of rows.
int num_row ;
num_row = get_num_row () ;
// Draw triangles
draw_tri ( this_char, num_row ) ;
return 0 ;
}
// Function to get number of rows.
int get_num_row ()
{
int num_row ;
cout << " Please enter the number of rows you would like in your triangle. " << endl ;
cin >> num_row ;
return num_row ;
}
// Function to draw triangles.
void draw_tri (char this_char, int num_row )
{
for ( int i = 1 ; i <= num_row ; i ++ )
{ // Nested loop.
for ( int j = 1 ; j <= i ; j ++ )
{
cout << " * " ;
}
cout << endl << endl ;
}
}
Comment