Printing all columns of a matrix C++

So I can get the first column to print but am lost as to why the others will not, any help would be appreciated. I am VERY new to C++ so therefore may be very messy. It is part of a bigger project that I may have questions on but rather do as much as I can by myself, just getting flustered on this part.

Cheers!
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
27
#include <iostream>  
#include <stdlib.h> 
#include <time.h>
using namespace std;

void main() 
{ 
	int matrix[10][10], j=0, i=0;
	 
srand((unsigned int)time(NULL)); 
      
   for(int i=0; i<10; i++) 
   {
	   	   
		 for(int j=0; j<10; j++)
	   
	 
	    matrix[i][j]= (rand()%100+1);
	   }  
       for (int i = 0, j=0; i < 10, j <10; i++, j++)
	   {
  
  cout << matrix[i][j] << endl;
	   }
	
}
Notice how you initialized the matrix using two nested for loops, but you attempt to output the matrix using only one for loop. One of those two ways has to be wrong.
Is it possible that I need another void function to output the matrix? I see what you are saying but it doesn't seem to work when I try to manipulate another for loop into it, just makes the column 20 rows long instead of making a [10][10].

Printing loop

1
2
3
4
5
6
7
for(int i=0; i<10; i++) 
{
  for(int j=0; j<10; j++)
    cout << setw(4) << matrix[i][j];

  cout << endl;
}
thanks! Appreciate that a lot, just so I can learn what does the width have to do with it?
Prints out neater. Space + Number = 4. Remove it and see the difference
Topic archived. No new replies allowed.