Asterisk Printing (Rectangle)

Any idea on how to incorporate m * n?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
Write a complete program that reads integers m and n and character c from the console and outputs mn occurrences of the c arranged in a rectangle with m rows of n columns.
*/

#include <iostream>
using namespace std;

int main ()
{
int m, n;
char c;

cin >> m >> n >> c;

	for (int rows = 0; m <= 4; m++)
	{
		for (int columns = 0; n <= 6; n++)
		{
			cout << c;
		}
	}
	
return 0;
}

Last edited on
Hello andygarc1a,

You have the right concept, but the for loops are incorrect. The center part of the for loop should be rows < m and columns < n and after the inner for loop std::cout << endl; would be usefull to get to a new line.

Hope that helps,

Andy

P.S. Do not forget to change m++ and n++ to rows++ and columns++.
Last edited on
Topic archived. No new replies allowed.