I am trying to create a multi functional program. For one part, an array is filled with random numbers. The user then enters in a number and the program returns which positions the number appears in the array. It also returns the number of times the number appears in the array.
However it only does this once and after that it ends the program. I want it to prompt the user to enter in a number to search until the user presses a button, let's say 'P' for example. Once the user presses 'P' after the results are shown, the program should close. Any tips into what methods or functionality I should be using?
Here is a broken down version of my code.
Console.Write("Now enter a number to compare: ");
int c = Convert.ToInt32(Console.ReadLine());
for (int j = 0; j < arr.Length; j++)
{
if (arr[j] == c)
{
pos.Add(j);
}
}
if (pos.Count == 0)
{
Console.WriteLine("Sorry this number does not match");
}
else
{
Console.WriteLine("The number {0} appears {1} time(s)",c,pos.Count);
}
Console.ReadLine();