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?