Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi I'm creating a program that holds three arrays one for the persons last name, one for the points scored and one for the player number, now I've got all the arrays and everything done but I'm not sure as to how I'm going to delete an entry for multiple arrays. so far this is what I have for my delete player method. Some guidance in the right direction would really help please and thank you

C#
static Int32[] ProcessDelete(Int32[] playerNumbers, String[] playerLastName, Int32[] playerPoints, ref Int32 playerCount)
        {
            Int32[] newArray = new Int32[playerNumbers.Length - 1]; 

            int index = 0;
            int j = 0;
            while (index < playerNumbers.Length)
            {
                if (index != playerCount)
                {
                    newArray[j] = playerNumbers[index];
                    j++;
                }

                index++;
            }

            return newArray;          
           
        }

        static void DeletePlayer(Int32[] playerNumbers, String[] playerLastName, Int32[] playerPoints, ref Int32 playerCount, Int32 MAXPLAYERS)
        {
            int player;// Player number to delete
            int playerindex;//index of the player number in Array
            if (playerCount < MAXPLAYERS)
            {
               
                player = GetPositiveInteger("\nDelete Player: please enter the player's number");
                playerindex = GetPlayerIndex(player, playerNumbers, playerCount);
                
                if (playerindex != -1)
                {
                    
                    {    
                        
                        Console.WriteLine("\nDelete Player: Number - {0}, Name - {1}, Points - {2}", playerNumbers[playerindex], playerLastName[playerindex], playerPoints[playerindex] );
                        Console.WriteLine("Succesfully Deleted");
                        Console.WriteLine();
                        
                    }
                }
                else
                    Console.WriteLine("\nDelete Player: player not found");
            }
            else
                Console.WriteLine("\nDelete Player: the roster is empty");
        }
        
    }
}
Posted
Updated 2-Nov-14 6:32am
v2
Comments
BillWoodruff 2-Nov-14 12:33pm    
Do you want some advice that would involve changing the way you are storing the data now ?
Afzaal Ahmad Zeeshan 2-Nov-14 12:35pm    
You can use some unique value that would identify the data which you can remove from the array.
PIEBALDconsult 2-Nov-14 12:40pm    
I _strongly_ advise you to embrace OOP and define a class to hold persons last name, points scored, and player number. Then make one array (or List) to hold them.

1 solution

OK, the situation you currently have is a direct sign that you need some re factoring in your code.

And before I go further, the question you have asked can be answered very easily and someone in this forum might do as well. However, I am sure that would just solve the short/immediate problem and you would be faced with another challenge soon.

The thing is that even though the data (number, name and point) is interrelated, you have not used them as a single entity but separate items and then just relying on the array index.

Instead, you should first focus on how to have a better structure/class which can store this information for you.

You could start something like this:

C#
class Player
{
	 public int Number {get; set; }
	 public string Name {get; set; }
	 public int Points {get; set; }
}


This gives you a object which stores the information for a player. If you have a new property tomorrow such as Player's age etc., you just need to add it here as a starting point.

Similarly, when you are processing deletes, you could start something like this:

C#
public void ProcessDelete(List<player> players)
{
	//your logic to delete a certain player here
}

C#
public void DeletePlayer(Player player)
{
	//your logic here
}

I hope this helps you to think further. Good luck!
 
Share this answer
 
v3
Comments
CHill60 2-Nov-14 12:46pm    
Good advice. +5
Manas Bhardwaj 2-Nov-14 12:47pm    
thank you :)
BillWoodruff 2-Nov-14 13:24pm    
+5 While I was waiting (before posting) for the OP to answer my comment, you served-up the goodies, fresh :) I was going to suggest using a struct, but, why not use a class.
Manas Bhardwaj 2-Nov-14 13:30pm    
Thanks Bill!

Yes, I could not stop myself looking at the code. He prob. will make it more simpler by using the pre-defined OOPS principles and in turn might have a good night sleep in coming days instead of just solving and debugging these issues again and again.
BillWoodruff 3-Nov-14 1:11am    
"Yes, I could not stop myself looking at the code." I know that feeling :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900