I am trying to create an application that prompts a user for 5 names, then display each name and allow the user to enter a score for that particular name. So if in the first array, the value for index [0] is a string “Bob”, then in the other array for scores index [0] should be the score for bob.
I am having a hard time understand how to pass the nameArray[] to the PopulateScore() method so that it can display the name for the user to enter a corresponding score.
I also have to search the Array by name and return the score.
Thanks for any help.
public class InitArraya
{
public static string[] arrayName = new string[5];
public static int[] arrayScore = new int[5];
public static void PopulateNameArray()
{
// Prompt user for names and assign values to the elements of the array
for (int intCounter = 1; intCounter < arrayName.Length; intCounter++)
{
Console.Write("Enter name {0}: ", intCounter);
arrayName[intCounter] = Console.ReadLine();
}
}
public static void PopulateScoreArray(string[] array)
{
// Prompt user for names and assign values to the elements of the array
for (int intCounter = 1; intCounter < 5; intCounter++)
{
Console.Write("Enter score for {0}: ", arrayName[0]);
arrayScore[intCounter] = Convert.ToInt32(Console.ReadLine());
}
}
public static void Main( string[] args )
{
Console.WriteLine("Enter 5 names:"); // headings
PopulateNameArray();
PopulateScoreArray(arrayName);
Console.ReadLine();
}
}
in
change
to
To use input array. Also in all for(-) change the start for counter to 0