3 Nisan 2013 Çarşamba

9 - İf Else İf... Mevsimler...

Form tasarımı aşağıdaki gibi olacaktır... 

Program çalıştığında ise aşağıdaki gibi bir sonuç alınacakıtr... 

Programın kodları aşağıdadır... 


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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Girilecek olan ayın numarasına göre mevsimleri söyleyecek olan program?
            int ay = Convert.ToInt32(textBox1.Text);

            // Eğer 1-12 arası sayı girdirilmiyorsa hata mesajı verdiriyoruz... 
            if (ay <= 12 && ay >= 1)
            {
                // Mevsimlere göre işlemlerimizi yapıyoruz... 
                if (ay >= 3 && ay <= 5)
                   MessageBox.Show("İLKBAHAR...");
                else if (ay >= 6 && ay <= 8)
                    MessageBox.Show("YAZ...");
                else if (ay >= 9 && ay <= 11)
                    MessageBox.Show("SONBAHAR...");
                else if (ay == 12 || ay == 1 || ay == 2) // Kış mevsiminde 3 şart olduğu için durum biraz daha farklı...
                    MessageBox.Show("KIŞ...");
            }
            else
                MessageBox.Show("HATA...");
        }
    }
}