E
E
evans_852020-11-01 21:09:45
C++ / C#
evans_85, 2020-11-01 21:09:45

How to use void type variable?

My knowledge of c# is limited) Explain how, after declaring an array, calculate the sum of the minimum and maximum values. Apparently my program is wrong, because an error pops up: it is impossible to convert a variable of type void to int.

static void Main(string[] args)
     { 
        double [] Data = new double[5];
        int i = 0;
       while (i < 5)
        {
           Data[i] = double.Parse(Console.ReadLine());
           Console.WriteLine();
           i++;
        }   
        int x =  
     Console.WriteLine(Data.Min());
        int y =
        Console.WriteLine(Data.Max());
        Console.WriteLine(x + y);
   }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-11-01
@evans_85

I would recommend that. Just look and think why

using System;
using System.Linq;

namespace ConsoleApp99
{
    internal class Program
    {
        private static void Main()
        {
            const int size = 5;
            var data = new double[size];
            var i = 0;
            Console.WriteLine("Enter float or double");
            do
            {
                var parsed = double.TryParse(Console.ReadLine(), out var dp);
                if (!parsed) continue;
                data[i] = dp;
                i++;
            } while (i < size);

            var x = data.Min();
            Console.WriteLine($"min: {x}");
            var y = data.Max();
            Console.WriteLine($"max: {y}");
            Console.WriteLine($"sum  x + y: {x + y}");
        }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question