Question

Thanks in advance: // File: main.cpp #include <iostream> #include <fstream> #include <iomanip> using namespace std; int...

Thanks in advance:

// 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 = '*';
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.
*/
  
  
  
  
  
  
}// end triangle()

Desired Output:
*
**
***
****
*****
****
***
**
*

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

// 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 = '*';

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(currentHeight<=maxHeight){

cout<<setw(currentHeight)<<drawChar<<endl;

triangle(drawChar, maxHeight, currentHeight+1);

if(currentHeight!=maxHeight)

cout<<setw(currentHeight)<<drawChar<<endl;

}

} // end triangle()

Add a comment
Know the answer?
Add Answer to:
Thanks in advance: // File: main.cpp #include <iostream> #include <fstream> #include <iomanip> using namespace std; int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT