I'm trying to write a function that will draw a right triangle that will ascend and then descend after the max height is reached. It is to be drawn using the asterisk symbol. I'm fairly new to recursion and that is the primary method I need to use to solve this problem. Any guidance or critique to my code would be appreciative. I can only edit the code that is marked TODO.
// File: main.cpp
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int recursiveCount = 0;
void triangle(const char drawChar, const int maxHeight, const int currentHeight);
int main() {
char drawChar = '*';
/* Change the fill character to be the 'drawChar' used for the triangle. */
recursiveCount = 0;
cout.fill(drawChar);
triangle(drawChar, 5, 1);
cout.fill(' ');
return 0;
}// end main()
void triangle(const char drawChar, const int maxHeight, const int currentHeight) {
/* DO NOT edit code */
cout.fill(drawChar);
recursiveCount += 1;
/* END of do not edit */
/* TODO (1):
* Draw a right expanding triangle, using 'drawChar' as the character.
* The maxHeight represents the final height of the triangle,
* whereas the currentHeight represents the height of each side.
*/
if (maxHeight <= 0){
return;
}
triangle(drawChar, maxHeight - 1, currentHeight + 1);
for(int i=0; i < currentHeight; i++){
cout << drawChar << endl;
}
}