![]() |
| | #1 |
| Registered User Join Date: Nov 2002
Posts: 79
| linking errors Code:
#include <iostream>
#include<ctime>
using namespace std;
void drawboard(int size, int sol);
void AddQueen(int size, int row, int boards, int sol);
int size;
int col[]; // column with the queen
bool colfree[16]; // is the column free?
bool upfree[16]; //is the upward diagonal free?
bool downfree[16]; //is the downward diagonal free?
int main() //starts main
{
int row = -1; //row whose queen is currently placed
int boards = 0; //number of positions investigated
int sol = 0; //number of solutions found
cout<<"What size board do you want?";
cin>>size;
int i;
for (i = 0; i < size; i++) colfree[i] = true;
for (i = 0; i < size; i++) {
upfree[i] = true;
downfree[i] = true;
}
AddQueen(size, row, boards, sol);
//add function to print board and count # of times ran
return 0;
}
//AddQueen: attempt to place a queen
void AddQueen(int size, int row, int boards, int sol)
{ //AddQueen
int c; //column being tried for the queen
float randnum; //random number for placing if queen
randnum=rand()%11;
boards++;
row++;
for (c = 0; c < 8; c++)
if (colfree[c] && upfree[row+c] && downfree[row-c+7]) {
col[row] = c; //put a queen in (row,c)
colfree[c] = false;
upfree[row+c] = false;
downfree[row-c+7] = false;
if (row == 7) //end condition
drawboard(size, sol);
else
AddQueen(size, row, sol, boards);
colfree[c] = true; //now backtrack by removing the queen
upfree[row+c] = true;
downfree[row-c+7] = true;
}
row--;
}
//drawboard: print a solution
void drawboard(int size, int sol)
{
int i, j;
sol++;
cout << "board ran" << sol << " times" <<endl;
cout << "-----------------" << endl;
for (i = 0; i < 8; i++) {//for
for (j = 0; j < col[i]; j++)
cout << " -";
cout << " Q";
for (j++; j < 8; j++)
cout << " -";
cout << endl;
}
cout << "-----------------" << endl;
}
__________________ This has been a public service announcement from GOD. 111 1111 |
| sentienttoaster is offline | |
| | #2 |
| Disturbed Boy Join Date: Apr 2003
Posts: 244
| And what are the error messages?
__________________ Nothing more to tell about me... Happy day =) |
| gustavosserra is offline | |
| | #3 |
| Registered User Join Date: Nov 2002
Posts: 79
| Linking... n queen.obj : error LNK2001: unresolved external symbol "int * col" (?col@@3PAHA) Debug/n queen1.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. n queen1.exe - 2 error(s), 0 warning(s) thems would be it
__________________ This has been a public service announcement from GOD. 111 1111 |
| sentienttoaster is offline | |
| | #4 |
| Disturbed Boy Join Date: Apr 2003
Posts: 244
| Again your compiler didnīt help you .The declaration of col array must have its size. Code: void drawboard(int size, int sol); void AddQueen(int size, int row, int boards, int sol); int size; int col[]; // column with the queen bool colfree[16]; // is the column free? bool upfree[16]; //is the upward diagonal free? bool downfree[16];
__________________ Nothing more to tell about me... Happy day =) |
| gustavosserra is offline | |
| | #5 |
| Registered User Join Date: Nov 2002
Posts: 79
| ok, that seemed to fix it. Thanks for now, I'm sure I will find trouble again
__________________ This has been a public service announcement from GOD. 111 1111 |
| sentienttoaster is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Linking errors | Zeeshan | C++ Programming | 1 | 02-22-2009 02:10 AM |
| HELP!!Why and How to solve this linking errors. | huwan | C++ Programming | 3 | 05-07-2007 06:30 AM |
| new to visual C++ - "unresolved external symbol" linking errors | ubermensch | C++ Programming | 8 | 04-27-2006 10:39 AM |
| Linking Errors | ForlornOdium | C++ Programming | 1 | 12-07-2003 10:24 PM |
| Linking Errors... | c++_n00b | C++ Programming | 9 | 06-08-2002 07:03 PM |