Hello everyone, newbie programmer here with a few questions.
Im trying to create a multi-dimensional array to represent a chessboard and I wanted to check my progress as I code, so I created a few functions to read the array and print the value of 0. I think my logic is flawed, but Im unable to find whats going wrong. My executable prints out 0's forever, so I know my parameters are wrong somewhere. Thanks for the help
/*
File:7_24.cpp
Date:4/13/08
Function: Knight's Tour Program
*/
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#define ROWS 8
#define COLUMNS 8
void read ( int a[][8] );
void print ( const int a [][8] );
int main()
{
int chessBoard [ ROWS ][ COLUMNS ];
read ( chessBoard );
print ( chessBoard );
return 0;
}
void read ( int a[][8] )
{
for ( int i = 0; i < 8; i++)
{
for ( int j = 0; j < 8; j++ )
{
a[j] = 0;
}
}
}
void print ( const int a[][8] )
{
for ( int i = 0; i < 8; i++)
{
for ( int j = 0; j < 8; j++ )
{
while (j < 8 )
{
cout << " " << a[j];
}
cout << " " << a[j];
cout << endl;
}
}
cout << endl;
}
Im trying to create a multi-dimensional array to represent a chessboard and I wanted to check my progress as I code, so I created a few functions to read the array and print the value of 0. I think my logic is flawed, but Im unable to find whats going wrong. My executable prints out 0's forever, so I know my parameters are wrong somewhere. Thanks for the help
/*
File:7_24.cpp
Date:4/13/08
Function: Knight's Tour Program
*/
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#define ROWS 8
#define COLUMNS 8
void read ( int a[][8] );
void print ( const int a [][8] );
int main()
{
int chessBoard [ ROWS ][ COLUMNS ];
read ( chessBoard );
print ( chessBoard );
return 0;
}
void read ( int a[][8] )
{
for ( int i = 0; i < 8; i++)
{
for ( int j = 0; j < 8; j++ )
{
a[j] = 0;
}
}
}
void print ( const int a[][8] )
{
for ( int i = 0; i < 8; i++)
{
for ( int j = 0; j < 8; j++ )
{
while (j < 8 )
{
cout << " " << a[j];
}
cout << " " << a[j];
cout << endl;
}
}
cout << endl;
}