Search code examples
c#arraysmaxhighestconsole.readline

Get highest number from inputs


I need a programm, where I can type in numbers and in the end it gives me the highest number. Why doesn't it work like that? What do I need to change?

public class Program
{
    public static void Main()
    {
        double[] input = new double[12];
        for (int i = 1; i <= 12; i++)
        {
            Console.Write(" Type in {0} number:", i);
            input = [Convert.ToInt32(Console.ReadLine())];
        } 

        Console.WriteLine("The highest number is {0}", input.Max(element => Math.Abs(element)));

        Console.ReadKey();
    }
}

Solution

  • You need to make it so its converting to double and also setting to each individual element

     input[i] = Convert.ToDouble(Console.ReadLine());
    

    and then change this because arrray starts at 0

    for (int i = 0; i <= 11; i++)