Please help me with the task: "Find maximum in the array"

Hello, I’m working on this task:

Call a method GetNumbersFromConsole that reads a count value of double, and then reads count values from the console into a double array. Find the maximum of the values in the array and print “Max is: {number}” to the console. For example:
>3
>1.12
>-2.333
>399.76
Max is: 399.76

Here is my code:

using System;

namespace Arrays
{
   class MaxInArray
   {
       public static void Main(string[] args)
       {
           double[] numbers = GetNumbersFromConsole();
           double number = numbers[0];
           for (int i = 0; i < numbers.Length; i++)
           {
               if (numbers[i] > number)
                   number = numbers[i];
           }

           Console.WriteLine($"Max is:{number}");

       }

       static double[] GetNumbersFromConsole()
       {
           int count = int.Parse(Console.ReadLine());
           double[] result = new double[count];

           for(int i = 0; i < count; ++i)
           {
               result[i] = double.Parse(Console.ReadLine());
           }

           return result;
       }
   }
}

Somehow it doesn’t accept the task quoting “Task solution resolut: FAIL”
Can anyone please help me to solve it?

Hi, the problem is in a missing space between the is: and the output number. It should be:
Console.WriteLine($"Max is: {number}");

I want to say sorry for Codeasy behavior, we worked a lot on issues like this, and still, Codeasy is not as smart as we want it to be. So sometimes it expects an exact output, as asked in the task description. I know this is frustrating and we are looking for ways to make the system smarter.

What we have today is a hint written in blue, which says: ‘You output string is almost correct’

thanks, got it all working now

1 Like

using System;

namespace Arrays
{
class MaxInArray
{
public static void Main(string[] args)
{
double[] numbers = GetNumbersFromConsole();
if (numbers.Length > 0)
{
double max = numbers[0];
for (int i = 1; i < numbers.Length; ++i)
{
if (numbers[i] > max)
max = numbers[i];
}
Console.WriteLine($“Max is: {max}”);
}
}

    static double[] GetNumbersFromConsole()
    {
        int count = int.Parse(Console.ReadLine());
        double[] result = new double[count];

        for(int i = 0; i < count; ++i)
        {
            result[i] = double.Parse(Console.ReadLine());
        }

        return result;
    }
}

}Heres the correct code!