I am attempting to write a C# program (in visual studio) that takes some numbers as keyboard input and prints which of them is the smallest and largest. This is a homework assignment and I intend to use only the things covered in the class up to this point. So, I am quite aware that this could be done in a much simpler way with an array and the MATH.min and max methods. However, the point of this program is just to practice if/else logic. Anyway, the logic is not my issue. The code below works as intended until the final user entered number is input, then it just closes without printing the final writeline statement used to show the results. Is there something that needs to be done to fix this? Thanks!
using System;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
double maxNum = 0;
double minNum = int.MaxValue;
int numToEnter;
int enterCounter = 0;
double currentNum;
Console.Write("How many numbers will be entered?: ");
numToEnter = int.Parse(Console.ReadLine());
while (enterCounter < numToEnter)
{
Console.Write("Enter a positive number: ");
currentNum = double.Parse(Console.ReadLine());
if (currentNum >= 0)
{
if (currentNum >= maxNum)
{
maxNum = currentNum;
}
if (currentNum < minNum)
{
minNum = currentNum;
}
enterCounter++;
}
else
{
Console.Write("Please enter a positive number: ");
}
}
Console.WriteLine("The largest number is: {0}. The lowest number is: {1}", maxNum, minNum);
}
}
}