I am required to write a program that reads data into an array of type int. Valid values are from 0 to 10. your program should determine how many values were input. Output a list of distinct entries and a count of how many times that entry occurred.”
I’m having trouble with the bolded part, this is what i have so far…
static void Main(string[] args)
{
Console.WriteLine("How many scores will you enter?");
int total = 0;
string inValue;
string Size = Console.ReadLine();
int arraySize = Convert.ToInt32(Size);
int [] ScoreArray = new int [arraySize];
for (int i = 0; i < ScoreArray.Length; i++)
{
Console.Write("Enter a Number between 0 and 10, #{0}: ", i + 1);
inValue = Console.ReadLine();
ScoreArray[i] = Convert.ToInt32(inValue);
total += ScoreArray[i];
}
Console.WriteLine("Number of scores entered: " + arraySize);
Console.Read();
}
I think the key here is valid values are between 0-10. I would use the array index to store each value itself. For example, if you process the value 5, increment
values[5].So first you’d initialize an array like:
Then, loop until the user just enters blank:
You can then display a sorted distinct list by looping through the array once and printing out any index with a value greater than 0:
This is most likely what your professor is looking for. I have not tested the code above, that’s your job 🙂