我设置了一个线性搜索算法来搜索它工作的类对象数组,但输出不匹配,当我在数组中搜索特定名称时,找到数组中的第一个和第三个值,但第二个值是未找到。
以下是我的代码,感谢您的帮助。
int linsearch(string val)
{
for (int j=0; j <= 3; j++)
{
if (player[j].getLastName()==val)
return j ;
}
return 1 ;
}
void showinfo()
{
string search;
int found ;
cout << "Please Enter The Player's Last Name : " ;
cin >> search ;
found=linsearch(search);
if (found==1)
{
cout << "\n There is no player called " << search ;
}
else
{
cout << "\n First Name : " << player[found].getFirstName() << "\n" << "Last Name : " << player[found].getLastName() <<
"\n" << "Age : " << player[found].getAge() << "\n" << "Current Team : " << player[found].getCurrentTeam() <<
"\n" << "Position : " << player[found].getPosition() << "\n" << "Status : " << player[found].getStatus() << "\n\n";
}
cin.get() ;
menu() ;
}