Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi , it is my Sudoku code . it has 2 errors but everything i search i can't solve this error . i need your kind helping to solve these errors to can run my program.

C++
#include <iostream>
#include <conio.h>

int a[9][9], b[9][9];
int inputvalue(int x, int y, int value)
{
	//scanning horizontally and vertically
	for (int i = 0; i < 9; i++)
	{
		if (value == b[x][i] || value == b[i][y])
			return 0;
	}
	//scanning its owne squares
	for (int i = (x / 3) * 3; i <= ((x / 3) * 3) + 2; i++)
	for (int j = (y / 3) * 3; j <= ((y / 3) * 3) + 2; j++)
	if (b[i][j] == value)
		return 0;
	return value;
}

int solve(int x, int y)
{
	int temp;
	if (b[x][y] == 0)
	{
		for (int i = 1; i < 10; i++)
		{
			temp = inputvalue(x, y, i);
			if (temp>0)
			{
				b[x][y] = temp;
				if (x == 8 && y == 8)
					return 1;
				else if (x == 8)
				{
					if (solve(0, y + 1))
						return 1;
				}

				else
				{
					if (solve(x + 1, y))
						return 1;
				}

			}
			if (i == 10)
			{
				if (b[x][y] != a[x][y])
					b[x][y] = 0;
				return 0;
			}
		}
		if (x == 8 && y == 8)
			return 1;
		else if (x == 8)
		{
			if (solve(0, y + 1)) return 1;
		}
		else
		{
			if (solve(x + 1, y)) return 1;
		}

	}
	return 0;
}

void gotoxy(int i, int i1);

int main()
	{

		int i, j;
		for ( i = 0; i < 9; i++)
		for ( j = 0; j < 9; j++)
		{
			gotoxy(i + 1, j + 1);
			std::cin>> a[i][j];
		}
		for ( i = 0; i < 9; i++)
		for (j = 0; j < 9; j++)
			b[i][j] = a[i][j];

		if (solve(0, 0))
		{
			for (i = 0; i < 9; i++)
			for ( j = 0; j < 9; j++)
			{
				gotoxy(i + 1, j + 1);
				std::cout << b[i][j];
			}
		}
		else
			std::cout << "no soln";
		
			_getch();
			return 0;
	}



the errors are:

1)error LNK2019: unresolved external symbol &quot;void __cdecl gotoxy(int,int)&quot; (?gotoxy@@YAXHH@Z) referenced in function _main

2)error LNK1120: 1 unresolved externals


thanks

What I have tried:

i have tried a lot via re sharper and google . but i don't know what to do anmore .please help me pleaseeee
Posted
Updated 24-Feb-16 3:25am
v2

There is no definition (implementation) of the function gotoxy().

You only have a declaration
void gotoxy(int i, int i1);


But you need also
void gotoxy(int x, int y)
{
    // Implement code here
    // UPDATE: With Windows you can use (include Windows.h)
    COORD coord;
    coord.X = x; 
    coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

The function is not a standard function but was provided with old Compilers. When using a modern compiler you must implement it yourself.
 
Share this answer
 
v2
Comments
Lida Zareian 24-Feb-16 10:01am    
my errors got finished thanks but when i given true numbers as inputs ... it always says no solution ... why??
Jochen Arndt 24-Feb-16 10:11am    
That requires stepping into the code and analysing it.

You may use the debugger to step through the code watching what is executed to find out where the behaviour is not as intended.

As a first check you might also print out the values when solving fails.
Lida Zareian 24-Feb-16 10:27am    
i did but couldn't understand where is the problem .pleas help me
Jochen Arndt 24-Feb-16 10:42am    
I'm sorry but that is not how it works here.

I (and others here) don't have the time to understand your code and find out where it does not work as expected.

We will help with specific problems but such tasks have to be done by the one who wrote the code.

So you have some input values and know the correct result.
Step through the code using the debugger and write down the intermediate results. You should notice when an intermediate result is not as expected.
Philippe Mori 24-Feb-16 13:05pm    
At first, it look like your code is oversimplified. For most Sudoku, you either need more elaborated algorithm or do back-tracking...
Simple, Read the error message:
Quote:
1)error LNK2019: unresolved external symbol "void __cdecl gotoxy(int,int)" (?gotoxy@@YAXHH@Z) referenced in function _main
The compiler tells you that he don't know your function gotoxy.
One cas see that there is a protype
C++
void gotoxy(int i, int i1);

but is the code for gotoxy ?
 
Share this answer
 
Comments
Lida Zareian 24-Feb-16 9:29am    
this line Re-sharper suggest me then i created it by default to remove the error.
Jochen Arndt 24-Feb-16 9:32am    
[Nitpicking mode="on"]
The linker, not the compiler.
[Nitpicking mode="off"]

Anyway, my 5.
Lida Zareian 24-Feb-16 9:34am    
what should i do ? i didn't get you . sorry
Jochen Arndt 24-Feb-16 9:38am    
That comment was for ppolymorphe.
It is not the compiler telling you that the function is missing, but the linker.

When using Windows, see my solution what to do. When not using Windows, search for gotoxy using your platform to find an implementation and add that code to your source file.
Patrice T 24-Feb-16 10:03am    
Thank you.
Yes the linker, I didn't practice C++ in last 20 years :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900