I am trying to find the same value in an ArrayList.
For example if the user entered
1
1
1
2
2
3
4
5
I want the output to be like:
There are 3 1's
There are 2 2's
There is 1 3
There is 1 4
and so on.
This is what I have so far. Also I am not worrying about the output as far as "There are" or "There is" yet I just want to count the same values in the array elements.
using System;
using System.Collections;
using System.Text;
namespace Count_How_Many_values
{
class Program
{
static void Main(string[] args)
{
// Declare Variables
int intUserInputNumbers;
string strContinue;
ArrayList Numbers = new ArrayList();
do
{
Console.WriteLine("Please Enter Numbers 0 through 10");
intUserInputNumbers = Convert.ToInt32(Console.ReadLine());
if((intUserInputNumbers > 0) && (intUserInputNumbers < 11))
{
Numbers.Add(intUserInputNumbers);
Console.WriteLine("Press 'C' to continue");
strContinue = Console.ReadLine().ToUpper();
}
else
{
Console.WriteLine("Number was eithier below 0 or bigger then 10");
Console.WriteLine("");
Console.WriteLine("Press 'C' to continue");
strContinue = Console.ReadLine().ToUpper();
}
} while (strContinue == "C");
Console.Write("There are {0} ", Numbers.Count);
Console.WriteLine("numbers in our array");
Numbers.Sort();
DisplayArray(Numbers);
}
static void DisplayArray(ArrayList Numbers)
{
int intCounter;
int HowManyTimes;
for (intCounter = 0; intCounter < Numbers.Count; intCounter++)
Console.WriteLine(Numbers[intCounter]);
Console.WriteLine("");
}
}
}
Now I know I need to use 2 for loops in the DisplayArray Method
to do this. I need to find the value , count it and then flag it as already counted, but I have no idea how to do this.
Can anyone help me out?
Thanks in advance

New Topic/Question
Reply




MultiQuote







|