3 Nisan 2013 Çarşamba

7 - İf Else İf... Dört İşlemde Seçim...

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

Program çalıştığında ise aşağıdaki gibi bir sonuç ile karşılaşılacaktır...

Programın kodları ise aşağıdaki gibidir... Kodlar yine hesapla butonunun içerisine yazılmıştı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 sayılara seçime göre dört işlemi yaptıracak olan programdır... 
            double s1, s2;
             s1 = double.Parse(textBox2.Text);
             s2 = double.Parse(textBox3.Text);

             string islem = textBox1.Text; // Buraya girilen seçimi aldırıyoruz... 
             if (islem == "/")
                 MessageBox.Show("Bölme İşleminin Somucu = " + (s1 / s2));
            else if (islem=="*")
                 MessageBox.Show("Çarpma İşleminin Somucu = " + (s1 * s2));
            else if (islem=="-")
                 MessageBox.Show("Çıkarma İşleminin Somucu = " + (s1 - s2));
            else if (islem=="+")
                 MessageBox.Show("Toplama İşleminin Somucu = " + (s1 + s2));
        }
    }
}