- Yasaklandı
- #1
Öfke.
Seçkin Üye
Gerekenler : 2 button 7 textbox ve 7 label
Button 1 'in içine:
Kod:
private void 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 MessageBox’a Yazdırıyoruz…
break;//Burda 1’den fazla 100’den büyün not olduğunda her bir not için hata vermemesi için for’dan çıkıyoruz(for’u bırakıyoruz)..
}
if (not[j] <= 100)//Eğer girilen notlar 100’den 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[i] != 0)//Değeri 0 olmayan notları hesaplamaya dahil edicez…
{
top = top + not[i];//not’ların toplamını bulup top değişkenine atıyoruz…
h++;//burda kaçtane notun 0 ‘dan büyük olduğunu bulup h’ye 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) txtort’a yazdırıyoruz…
}
}
}
Button 2 'nin içerisine bu kodu yazıyoruz :
Kod:
private void 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();//cnt’ye TextBox’ların özelliklerini atıyıp TextBox’ları siliyoruz…
}
}
}
}
}
Programız hazır ve çalışmaktadır.