我一直试图将这个数组显示为6X6格式的网格,但它出现在一条直线上。我知道哪里出错了?
我需要它显示为
a s c g s f
g g j n j s
h v i e m a
请赐教,谢谢!
代码:
using namespace std;
int generateRand()
{ return rand() % 9000 + 1000; }
void arraynumbers()
{
int board[ 6 ][ 6 ];
int cols = 6;
int rows = 6;
srand( (unsigned) time( NULL ) );
for ( int b = 0; b < rows; b++ )
{
for ( int a = 0; a < cols; a++ )
{
cout << char( 218 );
for ( int i = 0; i < 4; i++ )
{
cout << char( 196 );
}
cout << char( 191 ) << endl;
cout << char( 179 ) << generateRand() << char( 179 ) << endl;
cout << char( 192 );
for ( int k = 0; k < 4; k++ )
{
cout << char( 196 );
}
cout << char( 217 ) << " " << endl;
}
}
}
int main()
{
arraynumbers();
cin.ignore();
}