Hi everyone!
I would like to ask for some ideas for the following code. It works well in general, but I doesn't work all the time. I have just been working on it for so long that I am out of ideas.
Basically it removes the elements from the array without any problems until I play with it too much, then it just takes my remove command and says that it has removed remove! And then everything falls apart.
Tee hee, I am a beginner, so please don't laugh to much at my horrible coding ways I am sure no one will like the last line of code, but it was the only way I could make this thing work.. I am certain there are better ways to do this.
I also am wondering how I would go about removing the array completely. I can erase the elements inside the array, but the array is still there, with no elements inside...
I thank you all for your time in advance.
Code:void CircleList::remove(string remove) // Returns Name that will be removed from the List { int j = 0; int loops=1; // To count number of loops int shift=1; // To count how many to shift in array if (isEmpty()) // If no Players in List { cout << "There are no players to remove."; } for (int i=last_player; i <= 10; i++) // Checking from current player to end of array { if (p[i].name==remove) // If a match { temp[i].name = p[i].name; // Put the name in temporary array loops=i; shift = loops - count; // Count the number of shifts to make break; // Get out of loop in case of double entry } } for (i=last_player; i >= 0; i--) // Checking from current player to beggining of array { if (p[i].name==remove) // If a match { temp[i].name = p[i].name; // Put name in temporary array loops=i; shift = count - loops; // Count the number of shifts to make break; // Get out of loop in case of double entry } } cout << p[i].name << " has been deleted." << endl; while (j !=shift) // While there are still shifts to do { p[i].name=p[i+1].name; // Shift up i++; j++; } count=count-1; // Decrease the number of players by 1 for (i=0; i<count; i++) // As long as there are players { temp[i].name=p[i].name; // Put them in temporary array } p[i].name=temp[i].name; // Switch temporary array to array last_player = last_player-1; // This is the new current player if (last_player == -1) // If last player "points" below 0 { last_player = count -1 ; // Bring it back to last element in array } p[10].name=""; // Ensures nothing is in index 10 }