Pattern printing beginner [help]

What other codes must I know to have "void print(int numberOfRows, int numberOfCols, char charUsed);" and "print(3, 4, ‘*’);" print out this pattern:

****
****
****

Below is what I came up with so far. Please give me guidance.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>

using namespace std;

int * rows,* cols;
char asg;
void print(int rows, int cols, char asg);

void print(int rows, int cols, char asg){
	
	print(3, 4, '*');
	}


int main(){
	
print(rows, cols, asg);

	return 0;
	}



Last edited on
you need a pair of loops (it can be done in one, but lets start simple) and a print statement.
to write out a single * you might try

cout << '*';
and to write an end of line try
cout << endl;

and something like
for(j = 0; j < numrows; j++)
{
for(k = 0; k< numcols; k++)
cout << '*'; //this is in the inner loop.
cout << endl; //this is in the outer loop.
}

try to avoid using globals. Also the global pointers are not used correctly here.
also, rows and cols in main are not initialized. Keep it simple, try
print(3,4, asg); //what is asg for?? it is not used.

Last edited on
Thanks, I'll remember to avoid global declarations!
Topic archived. No new replies allowed.