一共三点编译错误,如下:
第一点错误,包含的头文件拼写错了:
应该是:#include
第二点错误,类型不匹配:
常量N是const int类型,而fillarray得第二个参数是int的引用。非const类型是不能赋值给const类型的,编译器不允许这种限制降低的赋值,因此需要修改fillarray的定义,第二个参数为const int& length。就可以了。
第三点错误,还是拼写错误:
b=result(arrrayA,N,a);这行中的arrrayA多了一个字母r
修正后可以运行的程序如下:
#include
using namespace std;
const int N=20;
void fillarray(int list[],const int & length)
{int counter;
for(counter=0;counter
}
int result(int list[],int length2,int searchItem)
{int loc;
bool found =false;
for (loc=0;loc
{
found=true;
break;
}
if (found)
return loc ;
else
return -1;
}
int main ()
{
cout<<"The numbers you want to deal are:"<
cin>>a;
int b=0;
int arrayA[N];
fillarray(arrayA,N);
b=result(arrayA,N,a);
if (b>=0)
cout<<"location is "< else
cout<<"Wrong!";
return 0;
}
有一些语法错误。
头文件为
函数fillarray()第二个参数传递的是N,为常量,声明时却为int &,应改为const int类型。
调用result()函数时传递的是arrayA,多了字母r。
建议,代码有一定的缩进,方便阅读。注意输入的准确性。(纯粹个人看法)