creating grid(matrix), C++

Hi
i'm trying to write a program that print a grid (as many as the user inputs).
For example if the user chooses to print 5x5 grid it prints it with random numbers.
My problem is after i compile it prints the grid all in one line, which is not what I want, I want it to print it as matrix(grid).

Here's my code
1
2
3
4
5
6
  


and here is the program(compiled) after I use the command line argument ./grid 5 5
[code]
83 86 77 15 93 35 86 92 49 21 62 27 90 59 63 26 40 26 72 36 11 68 67 29 82

Last edited on
someone just replied then deleted his/her post! where is it.
1
2
3
4
5
6
7
8
void print_grid(int **grid, int w, int h){
	for(int i=0; i < w; i++){
		for(int j=0; j < h; j++){
			cout << grid[i][j] << " ";
		}
        cout<<endl;
	}
}


Put a new line at the end of each row
THANK YOU. that worked!
Topic archived. No new replies allowed.