C# Not Ortalaması Hesaplama
Gereken nesneler ;
2 Button
7 Textbox
7 Label
BUTTON1 İçerisine ekleyeceğimiz kod;
private **** button1_Click(object sender, EventArgs e)
{
double[] not = new double[6];
double ort = 0, h = 0, top = 0;
not[0] = double.Parse(textBox1.Text);
not[1] = double.Parse(textBox2.Text);
not[2] = double.Parse(textBox3.Text);
not[3] = double.Parse(textBox4.Text);
not[4] = double.Parse(textBox5.Text);
not[5] = double.Parse(textBox6.Text);
for (int j = 0; j < 6; j++)//for ile bütün girilen notları kontrol edicez
{
if (not[j] > 100)
{
textBox7.Clear();
MessageBox.Show(Notlarınızı Kontrol Ediniz
, Hata..!, MessageBoxButtons.OK, MessageBoxIcon.Error);//burada MessageBoxa Yazdırıyoruz
break;//Burda 1den fazla 100den büyün not olduğunda her bir not için hata vermemesi için fordan çıkıyoruz(foru bırakıyoruz)..
}
if (not[j] <= 100)//Eğer girilen notlar 100den küçük ise buradaki kodlar uygulanıcak
:
{
for (int i = 0; i < not.Length; i++)//for ile bütün girilen notları kontrol edicez
{
if (not != 0)//Değeri 0 olmayan notları hesaplamaya dahil edicez
{
top = top + not;//notların toplamını bulup top değişkenine atıyoruz
h++;//burda kaçtane notun 0 dan büyük olduğunu bulup hye aktarıyoruz
}
}
ort = top / h;//top değişkenini h değişkenine bölüp ort değişkenine atıyoruz
textBox7.Text = + ort;//ortalamayı(ort değişkenini) txtorta yazdırıyoruz
}
}
}
BUTTON2 İçerisine ekleyeceğimiz kod;
private **** button2_Click(object sender, EventArgs e)
{
foreach (Control cnt in this.Controls)//Formdaki bütün araçları kontrol ediyoruz
{
if (cnt is TextBox)//Eğer kontrol edilen araç TextBox ise buradaki kodlar uygulanır
:
{
(cnt as TextBox).Clear();//cntye TextBoxların özelliklerini atıyıp TextBoxları siliyoruz
}
}
}
}
}