I created a player class and I am trying to use my player class to update a player for my menu driven player program. I want to be able to have the user enter a player number and ask if they want to update the player assists and goals then display the updated player information and if the player doesn't exist then it would display the message player does not exist. For some reason when I enter a player number of one of the players I created when it gets to the edit goals Y/N and I chose Y it says the player doesn't exist instead of letting me edit the goals.it still says that the player does not exist even though it was just created. I am not sure on how to fix this.
Any help would be appreciated.
static void ProcessUpdate(Int32 number, String firstName, String lastName, Int32 goals,
Int32 assists, Player[] players, ref Int32 playerCount, Int32 MAXPLAYERS)
{
int playerindex;
string answer, answer2;
if (playerCount < MAXPLAYERS )
{
Console.WriteLine("\nUpdate Player: please enter the player's number");
number = Int32.Parse(Console.ReadLine());
playerindex = GetPlayerIndex(number, firstName, lastName, goals, assists, players, ref playerCount);
if (playerindex != -1)
{
Console.WriteLine("\nUpdate Player: Player {0} currently has {1} goals and {3} assists", players[playerindex].Number,
players[playerindex].Goals, players[playerindex].Assists, players[playerindex].Points());
Console.ReadLine();
Console.WriteLine("\nEdit Goals?: Y/N");
answer = Console.ReadLine();
if (answer.Equals('Y'))
{
Console.WriteLine("\nUpdate Player: please enter the player's new Goal total");
goals = Int32.Parse(Console.ReadLine());
Console.WriteLine("\nEdit Assists?: Y/N");
answer2 = Console.ReadLine();
if (answer2.Equals('Y'))
{
Console.WriteLine("\nUpdate Player: please enter the player's new Assists total");
assists = Int32.Parse(Console.ReadLine());
Console.WriteLine("\n{0,7} {1,-20}{2, -20}{3,8}{4,8}{5,8}\n", "Number", "First Name", "Last Name", "Goals", " Assists", "Points");
Console.WriteLine("{0,7} {1,-20}{2, -20}{3,8}{4,8}{5,8}",
players[playerindex].Number, players[playerindex].FirstName, players[playerindex].LastName,
players[playerindex].Goals, players[playerindex].Assists, players[playerindex].Points());
Console.WriteLine("Sucessfully Updated!");
Console.WriteLine();
}
}
else
Console.WriteLine("\nUpdate Player: the player number does not exists");
}
else
Console.WriteLine("\nUpdate Player: the player does not exist in the roster");
}
}