Edited:
I was using LINQ, to get rid of the 0 but, I just found out that I'm not allowed to use it (yes homework). Well, now I can't figure out why, when I input 0, the program still adds it to the array of numbers. Any suggestions?
static void Main(string[] args)
{
int first, second;
first = second = int.MaxValue;
int[] numbers = new int[10];
Console.WriteLine("Enter 2-10 numbers, end early with 0: ");
for (int i = 0; i < numbers.Length; i++)
{
int.TryParse(Console.ReadLine(), out int input);
if (input == 0) break;
numbers[i] = input;
}
if (numbers.Length < 2)
{
Console.Write("Please enter atleast 2 numbers");
goto finish;
}
Small(first, second, numbers);
finish:
Console.ReadLine();
}
private static void Small(int first, int second, int[] numbers)
{
for (int i = 0; i < numbers.Length; i++)
{
if (numbers[i] < first)
{
second = first;
first = numbers[i];
}
else if (numbers[i] < second && numbers[i] != first)
{
second = numbers[i];
}
}
if (second == int.MaxValue)
{
Console.Write("Please Enter At least 2 Diffrent Numbers");
}
else
{
Console.Write("Second Lowest Number is {0}", second);
}
}
The output is now fine.