Thory Forum



Join the forum, it's quick and easy

Thory Forum

Thory Forum

Would you like to react to this message? Create an account in a few clicks or log in to continue.
Thory Forum

Mekani


    Tek Textbox İle Matematik İşlemleri Yapma

    Cyber-Coder
    Cyber-Coder
    Co Admin
    Co Admin


    Mesaj Sayisi : 14
    Kayıt tarihi : 21/12/12

    Tek Textbox İle Matematik İşlemleri Yapma  Empty Tek Textbox İle Matematik İşlemleri Yapma

    Mesaj tarafından Cyber-Coder Ptsi Ocak 07, 2013 9:21 am

    Forma;
    1 button
    1 label - label in namesini lblSonuc
    1 textbox - textboxın namesini txtSayilar olarak değiştirelim.
    buttona çift tıklayıp kodları yazalım
    int toplam = 0;
    int fark = 0;
    int carpim = 0;
    int bolum = 0;
    try
    {
    string text = txtSayilar.Text.Trim();
    string[] toplama = text.Split('+');

    if (text.IndexOf('+') > 0)
    {
    foreach (var item in toplama)
    {
    toplam = toplam + int.Parse(item);
    }
    lblSonuc.Text = toplam.ToString();
    }
    else if (text.IndexOf('-') > 0)
    {
    int sayi1 = int.Parse(text.Substring(0, text.IndexOf('-')));
    string kalan = text.Substring(text.IndexOf('-') + 1);
    int sayi2 = int.Parse(kalan);
    fark = sayi1 - sayi2;
    lblSonuc.Text = fark.ToString();
    }
    else if (text.IndexOf('*') > 0)
    {
    int sayi1 = int.Parse(text.Substring(0, text.IndexOf('*')));
    string kalan = text.Substring(text.IndexOf('*') + 1);
    int sayi2 = int.Parse(kalan);
    carpim = sayi1 * sayi2;
    lblSonuc.Text = carpim.ToString();
    }
    else if (text.IndexOf('/') > 0)
    {
    int sayi1 = int.Parse(text.Substring(0, text.IndexOf('/')));
    string kalan = text.Substring(text.IndexOf('/') + 1);
    int sayi2 = int.Parse(kalan);
    bolum = sayi1 / sayi2;
    lblSonuc.Text = bolum.ToString();
    }
    }
    catch (Exception f)
    {
    MessageBox.Show("Hata" + f.ToString());
    }

      Forum Saati Paz Mayıs 19, 2024 10:26 am