Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question