the assignment asks me to find the second lowest number from the user input (max 10), and if a 0 is entered the program should stop and find the second lowest, without counting. But I have to declare the size of the array beforehand. For example, if I type in 4 7 3 8 0 the program also counts all the 0 until there are 10 numbers so it sees this: 4 7 3 8 0 0 0 0 0 0. Is there a way for me to stop the program from seeing the other 0 or to somehow change the array size?
Edit: Ok, so here is the code I have so far:
int s;
s = 10;
int[] numbers = new int[s];
for (int i = 0; i < numbers.Length; i++)
{
int.TryParse(Console.ReadLine(), out numbers[i]);
}
int firstLowestNumber = numbers[0];
int secondLowestNumber = numbers[0];
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] < firstLowestNumber)
{
firstLowestNumber = numbers[i];
}
}
for (int x = 0; x < numbers.Length; x++)
{
if (numbers[x] < secondLowestNumber && firstLowestNumber != numbers[x])
{
secondLowestNumber = numbers[x];
}
}
Console.WriteLine("Second Lowest Number is {0}", secondLowestNumber);
Console.ReadLine();