I have a problem with my code and I was wondering if someone could have a look, I have a function I have created to delete a specific element from an array. I use a linear search to find the element then I overwrite the element I want to get rid of with the one after as I have not found a way to delete an element specifically. my problem is that the code does not really work as the element does not get overwritten, also is there a way to leave an blank space in the array once the element has been overwritten.
below is my code:
void deleteinfo()
{
string search ;
int found ;
cout << "\n Delete A Player's Information \n\n" ;
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
{
player[found].getFirstName() = player[found + 1].getFirstName() ;
player[found].getLastName() = player[found + 1].getLastName() ;
player[found].getAge() == player[found + 1].getAge() ;
player[found].getCurrentTeam() = player[found + 1].getCurrentTeam() ;
player[found].getPosition() = player[found + 1].getPosition() ;
player[found].getStatus() = player[found + 1 ].getStatus() ;
cout << "\n Player has been deleted." ;
}
cin.get() ;
menu() ;
}
int linsearch(string val)
{
for (int j=0; j <= 3; j++)
{
if (player[j].getLastName()==val)
return j ;
}
return -1 ;
}