Nested Loops in Array

Joined
Apr 13, 2008
Messages
1
Reaction score
0
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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top