This may be a stupid question, but I can not figure it out.
using namespace std;
const int ROWS = 2;
const int COLS = 3;
int main()
{
cout << " First" << endl;
int first[ROWS][COLS] = {16, 18, 23,
54, 91, 11};
int rowNum, colNum;
for (rowNum = 0; rowNum < ROWS; rowNum++)
{
for(colNum = 0; colNum < COLS; colNum++)
{
cout << setw(4) << first[rowNum][colNum];
cout << endl;
}
}
cout << endl;
cin.ignore();
return 0;
}
For some reason my output looks like this:
First
16
18
23
54
91
11
When I need it to look like this:
First
16 18 23
54 91 11
The "some reason" is the statement
cout << endl; in the inner loop
1 2 3 4 5
|
for(colNum = 0; colNum < COLS; colNum++)
{
cout << setw(4) << first[rowNum][colNum];
cout << endl;
}
|
What you do is what you get. Any questions?
Last edited on
Wow, I shouldve spotted that. Thank you!
Last edited on