Şimdi Ara

Çalıştıramadığım Bir Kod Var Yardım Lazım

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
5
Cevap
0
Favori
251
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • c++ ile uğraşıyordum arkadaşlar, ancak benimkisi sadece hobi,
    bir süre sonra siyah ekran sıktı ve bıraktım, 1 2 gündür c# uğraşıyorum ve işin daha en başında sayılırım.
    Şu Satırı Kod içinde nereye eklersem ekliyim, bir türlü düzelmedi. Çalışıyor program ama textbox ı boş bıraktıktan sonra donuyor program ve görev yöneticisi ile kapatmak gerekiyor.
    O Satır ;
    if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") MessageBox.Show("Boş Alan Bırakılamaz");
    köşeli paranteze aldım, else if yaptım, en başa ekledm, en sona ekledm, ama bir türlü olmadı.
    bu da kod
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace Puana_Göre_Not
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {

    int not1, not2, not3, ort;
    not1 = int.Parse(textBox1.Text);
    not2 = int.Parse(textBox2.Text);
    not3 = int.Parse(textBox3.Text);
    ort = (not1 + not2 + not3) / 3;
    label6.Text = ort.ToString();
    if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") MessageBox.Show("Boş Alan Bırakılamaz");


    if(not1 > 100 || not2 > 100 || not3 >100 || not1 < 0 || not2 < 0 || not3 < 0)
    {
    MessageBox.Show("Yazılı Puanlarınız 0 ile 100 Arasında Olmalıdır");
    }
    else if (ort < 25 && ort >= 0)
    {
    label7.Text = "0";
    }
    else if(ort >= 25 && ort < 45)
    {
    label7.Text = "1";
    }
    else if (ort >= 45 && ort < 55)
    {
    label7.Text = "2";
    }
    else if (ort>= 55 && ort < 70)
    {
    label7.Text = "3";
    }
    else if (ort>=70 && ort < 85)
    {
    label7.Text = "4";
    }
    else if (ort >=85 && ort < 101)
    {
    label7.Text = "5";
    }
    else if (ort >= 101 || ort < 0)
    {
    MessageBox.Show("Ortalamanız 0 ile 100 Arasında Değer Almalıdır"); /* En Başa Eklediğim If
    * Komutu İle Bu Satırın Gerekliliği Ortadan Kalktı.Hiç Bir Şekilde Ortalama 0 dan Düşük Veya 100 den Yüksek
    *Çıkamayacak */
    }




    }







  • not1 = int.Parse(textBox1.Text);
    not2 = int.Parse(textBox2.Text);
    not3 = int.Parse(textBox3.Text);

    şimdi yukarıdaki kodları kontrolden önce yazmışsın, yani textboxlar boşsa donar tabiki program.Ayrıca kontrol ettiğin if satırında sadece uyarı veriyor çıkış yapacak bir kod yok.
    Kodu aşağıdaki gibi düzeltirsen sorun olmaz:

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace Puana_Göre_Not
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {

    if (String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox2.Text) || String.IsNullOrEmpty(textBox3.Text))
    {


    return;


    }



    int not1, not2, not3, ort;
    not1 = int.Parse(textBox1.Text);
    not2 = int.Parse(textBox2.Text);
    not3 = int.Parse(textBox3.Text);
    ort = (not1 + not2 + not3) / 3;
    label6.Text = ort.ToString();


    if(not1 > 100 || not2 > 100 || not3 >100 || not1 < 0 || not2 < 0 || not3 < 0)
    {
    MessageBox.Show("Yazılı Puanlarınız 0 ile 100 Arasında Olmalıdır");
    }
    else if (ort < 25 && ort >= 0)
    {
    label7.Text = "0";
    }
    else if(ort >= 25 && ort < 45)
    {
    label7.Text = "1";
    }
    else if (ort >= 45 && ort < 55)
    {
    label7.Text = "2";
    }
    else if (ort>= 55 && ort < 70)
    {
    label7.Text = "3";
    }
    else if (ort>=70 && ort < 85)
    {
    label7.Text = "4";
    }
    else if (ort >=85 && ort < 101)
    {
    label7.Text = "5";
    }
    else if (ort >= 101 || ort < 0)
    {
    MessageBox.Show("Ortalamanız 0 ile 100 Arasında Değer Almalıdır"); /* En Başa Eklediğim If
    * Komutu İle Bu Satırın Gerekliliği Ortadan Kalktı.Hiç Bir Şekilde Ortalama 0 dan Düşük Veya 100 den Yüksek
    *Çıkamayacak */
    }




    }




  • GUI istiyorsan C++ Qt Framework ile de yapabilirsin.



    < Bu mesaj bu kişi tarafından değiştirildi Reinhardt -- 24 Haziran 2014; 22:39:05 >
  • Yardımcı olduğunuz için saolun
    Hocam bu return komutunu, her yerde bu şekilde kullanabilir miyiz?
    Yani bu en başa mı döndürüyor yoksa if den önceki bölüme mi?



    < Bu mesaj bu kişi tarafından değiştirildi asdsaz -- 25 Haziran 2014; 0:33:12 >
  • asdsaz A kullanıcısına yanıt
    return içinde bulunduğun fonksiyonu sonlandırır ve istersen değer döndürür.

    public string DenemeString()
    {
    return "Deneme";
    }

    public void DenemeVoid()
    {
    return;
    }
  • Yapay Zeka’dan İlgili Konular
    Daha Fazla Göster
    
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.