using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnHesapla_Click(object sender, EventArgs e)
{
if (TryGetGrades(out double y1, out double y2, out double p1, out double p2))
{
double ort = CalculateAverage(y1, y2, p1, p2);
DisplayResult(ort);
}
else
{
lblOrtalama.Text = "Hatalı giriş.";
lblDurum.Text = "Hatalı giriş.";
lblDurum.ForeColor = Color.Black;
}
}
private bool TryGetGrades(out double y1, out double y2, out double p1, out double p2)
{
return double.TryParse(txtYazili1.Text, out y1) &&
double.TryParse(txtYazili2.Text, out y2) &&
double.TryParse(txtPerformans1.Text, out p1) &&
double.TryParse(txtPerformans2.Text, out p2);
}
private double CalculateAverage(double y1, double y2, double p1, double p2)
{
return (y1 + y2 + p1 + p2) / 4;
}
private void DisplayResult(double ort)
{
lblOrtalama.Text = ort.ToString();
if (ort >= 50)
{
lblDurum.Text = "GEÇTİNİZ";
lblDurum.ForeColor = Color.Green;
}
else
{
lblDurum.Text = "KALDINIZ";
lblDurum.ForeColor = Color.Red;
}
}
}
}