Simple 2D array problem...In a Hurry!
What exactly is wrong with this section of code. All I want to do is read in numbers into a 4X4 array and then output them to the screen in a 4X4 pattern. Please let me know what I am doing wrong ASAP. Thanks!
P.S. Is there a way to enter the numbers by row (separated by spaces) instead of each individual like I am doing? If so, how? Thanks again!
#include <iostream.h>
#include <iomanip.h>
int main()
{
int grid[4][4]={0};
bool magic = true;
int row, col;
for(row=0; row<4; row++)
{
for(col=0; col<4; col++)
{
cout << "Please enter the value for row " << row << ", col " << col << ": ";
cin >> grid[row][col];
}
}
for(row=0; row<4; row++)
{
for(col=0; col<4; col++);
{
cout << grid[row][col];
}
cout << endl;
}
return 0;
}
Re: Simple 2D array problem...In a Hurry!
Should be like this....
Code:
#include <iostream.h>
#include <iomanip.h>
int main()
{
int grid[4][4]={0};
bool magic = true;
int row, col;
for(row=0; row<4; row++)
{
for(col=0; col<4; col++)
{
cout << "Please enter the value for row " << row << ", col " << col << ": ";
cin >> grid[row][col];
}
}
for(row=0; row<4; row++)
{
for(col=0; col<4; col++) // THIS LINE! NO ;
{
cout << grid[row][col];
}
cout << endl;
}
return 0;
}
Semicolons after for loops declarations are no-no's.
Don't practice your hand to write "; "
Hi,
Don't used to do that because it is bad ...
it is bad ... because ones you used to it... even if you read your sintax for the first and the second and the third time ... you want be able to catch your mistake... but I think that the compiler should give you worning for that...
let me try it....
I know that you are in hurry ... but read that carfully...
:o