Thursday, November 27, 2014

how do i split an array of strings and ints.

i cant seem to figure out how to split the array of names and scores and display them in different Console.WriteLines. can anyone help point me in the right direction?



namespace proj09LEA
{
class Program
{
static void Main(string[] args)
{
// declare and array of integers
int[] array = new int[10];

Console.WriteLine("\nSaturday Coder's Bowling Team");
Console.WriteLine("Enter in a name and score for each person on the team.");
Console.WriteLine("For example, Mary 143. Just hit Enter when you are done.\n");

// fill an array with user input
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine("Enter in a name and score: ");
array[i] = int.Parse(Console.ReadLine());
}

Console.WriteLine("------------ Input Complete ------------\n");
Console.WriteLine("Here are the scores for this game:");

Console.WriteLine("{0}'s score was {1}.", array);

HighScore(array);
LowScore(array);
AverageScore(array);

Console.WriteLine("Press Enter to continue. . .");
Console.ReadLine();
}

static void HighScore(int[] array)
{
int max = array.Max();
Console.WriteLine("Congratulations {0}, your score of {0} was the highest.", max);
}

static void LowScore(int[] array)
{
int min = array.Min();
Console.WriteLine("{0}, your score of {0} was the lowest. Better get some practice.", min);
}

static void AverageScore(int[] array)
{
int sum = array.Sum();
int average = sum / array.Length;
Console.WriteLine("The average score for this game was {0:d}.", average);
}
}
}





Lyndsee Elizabeth



No comments:

Post a Comment