namespace ConsoleApp39
{
class Program
{
static void Main(string[] args)
{
Student[] students = new Student[3];
for (int i = 0; i < students.Length; i++) students[i].SetInfo();
Student.GetInfo(students);
}
}
struct Student
{
string LastName;
string FirstName;
int GroupNumber;
int[] scores;
public void SetInfo()
{
Console.WriteLine("Last name: ");
LastName = Console.ReadLine();
Console.WriteLine("Name: ");
FirstName = Console.ReadLine();
Console.WriteLine("Number: ");
while (!int.TryParse(Console.ReadLine(), out GroupNumber)) {
Console.WriteLine("Only number allowed");
};
Console.WriteLine("Scores: ");
scores = new int[5];
int inp;
for (int i = 0; i < scores.Length; i++)
{
while (!int.TryParse(Console.ReadLine(), out inp))
{
Console.WriteLine("Only number allowed");
};
scores[i] = inp;
}
}
public static void GetInfo(Student[] students)
{
foreach (var student in students)
{
for (int i = 0; i < student.scores.Length; i++)
{
if (student.scores[i] <= 2)
{
Console.WriteLine($"Last name: {student.LastName}\n name: {student.FirstName}\n Group: {student.GroupNumber}");
}
}
}
}
}
}
var ints = new[] { 22, 55, 11, 33, 77, 66 };
// вариант 1
var avg1 = ints.Where(a => a != ints.Max() && a != ints.Min()).Average();
// вариант 2
var avg2 = ints.Except(new[] { ints.Max(), ints.Min() }).Average();
Console.WriteLine(avg1); // 44
Console.WriteLine(avg2); // 44
var nums = new[] { 100, 3, 102, 7, 1, 9, 12 };
var max = default(int?);
var min = default(int?);
var avg = 0.0;
var avgCount = 0;
foreach (var number in nums)
{
if (min == null)
{
min = number;
}
else if (max == null)
{
max = number;
if (max < min)
{
max = min;
min = number;
}
}
else if (number < min)
{
avg = ((avg * avgCount) + min.Value) / ++avgCount;
min = number;
}
else if (number > max)
{
avg = ((avg * avgCount) + max.Value) / ++avgCount;
max = number;
}
else
{
avg = ((avg * avgCount) + number) / ++avgCount;
}
}
Хочу реализовать проверку корректности всех входных данных в поля регистрации и после нажатия на кнопку Registrationход мыслей понятен, типичен для новичка. но не лучший