This simple console program prompts the users for a number and returns the lowest and highest numbers from their inputs. It is difficult to add more user inputs, though. How can I make this easier to maintain and extend?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int num1 = 0, num2 = 0, num3 = 0;
Console.WriteLine("lowest");
Console.WriteLine("input 1st number");
num1 = int.Parse(Console.ReadLine());
Console.WriteLine("input 2nd number");
num2 = int.Parse(Console.ReadLine());
Console.WriteLine("input 3rd number");
num3 = int.Parse(Console.ReadLine());
Console.WriteLine("input 4th number");
num4 = int.Parse(Console.ReadLine());
Console.WriteLine("input 5th number");
num5 = int.Parse(Console.ReadLine());
Console.Clear();
int lowest = ((num1 < num2 ? num1: num2) < num3 ?
(num1 < num2 ? num1 : num2) : num3);
int highest = ((num1 > num2 ? num1: num2) > num3 ?
(num1 > num2 ? num1 : num2) : num3) ;
Console.WriteLine(" lowest is {0} ", lowest);
Console.WriteLine(" highest is {0} ", highest);
Console.ReadLine();
}
}
}
num4
andnum5
are read in but never used (or declared for that matter) in the lowest/highest calculation. \$\endgroup\$