请帮我解决c ++中数独程序的这些错误 [英] Please help me to solve these errors of sudoku program in c++
问题描述
这是我的数独代码。它有2个错误,但我搜索的一切都无法解决这个错误。我需要你帮助解决这些错误才能运行我的程序。
# include < iostream >
#include < conio.h >
int a [ 9 ] [ 9 ],b [ 9 ] [ 9 ];
int inputvalue( int x, int y, int value )
{
// 水平和垂直扫描
(< span class =code-keyword> int i = 0 ; i< 9 ; i ++)
{
if ( value == b [x] [ i] || value == b [i] [y])
return 0 跨度>;
}
// 扫描其所有方格
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;
如果(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 + < span class =code-digit> 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 ;
}
}
如果(x == 8 & & y == 8 )
return 1 跨度>;
else if (x == 8 )
{
if (solve( 0 ,y + < span class =code-digit> 1 )) return 1 ;
}
其他
{
如果(解决) (x + 1 ,y)) return 1 跨度>;
}
}
返回 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 + < span class =code-digit> 1 );
std :: cin>>一个[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];
}
}
其他
std :: cout<< no soln;
_getch();
return 0 ;
}
错误是:
1)错误LNK2019:未解析的外部符号& quot; void __cdecl gotoxy(int,int)& quot; (?gotoxy @@ YAXHH @ Z)函数_main
2)错误LNK1120:1未解析的外部
谢谢
我的尝试:
i已经通过锐化和谷歌尝试了很多。但我不知道该怎么办。请帮助我pleaseeee
函数的定义(实现)gotoxy( )
。
你只有声明
void gotoxy(int i, int i1);
但你还需要
void gotoxy(int x ,int y)
{
//这里实现代码
//更新:使用Windows,你可以使用(包括Windows.h)
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
该函数不是标准函数,而是由旧编译器提供。使用现代编译器时,必须自己实现。
简单,阅读错误信息:
编译器告诉你他不知道你的功能Quote:1)错误LNK2019:未解析的外部符号void __cdecl gotoxy(int,int)(?gotoxy @@ YAXHH @ Z)在函数_main
gotoxy
。
一个cas看到有一个原型
void gotoxy( int i, int i1);
但是代码为gotoxy
?
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.
#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 "void __cdecl gotoxy(int,int)" (?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
There is no definition (implementation) of the functiongotoxy()
.
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.
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
void gotoxy(int i, int i1);
but is the code forgotoxy
?
这篇关于请帮我解决c ++中数独程序的这些错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!