C++20 sections · 1024 units
Open in Course

Problem: Print Rectangle

Using void functions

Write void printRectangle(int width, int height) that prints asterisks. Outer loop runs height times, inner prints width asterisks per row, then newline. Call printRectangle(5, 3) for 3 rows of 5 asterisks.

This function returns nothing. Its job is output, a side effect. This is a helper function pattern. If you need borders in a menu system, call this. Side effects are what void functions are for.