calculator 2
designlah from berikut ini;
listing program
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace cal2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static Double a = 0;
public static Double b = 0;
public static Double c = 0;
public static string bil = "0";
public static string operatornya = "";
public Double proseshasil(string operatornya)
{
switch (operatornya)
{
case "bagi": c = a / b;
break;
case "kali": c = a * b;
break;
case "tambah": c = a + b;
break;
default: c = a - b;
break;
}
return c;
}
private void Form1_Load(object sender, EventArgs e)
{
operatornya = "";
bil = "";
a = 0;
b = 0;
c = 0;
}
private void bkali_Click(object sender, EventArgs e)
{
if (a == 0)
{
a = Double.Parse(bil);
operatornya = "kali";
}
else
{
b = Double.Parse(bil);
a = proseshasil("kali");
operatornya = "kali";
}
bil = "";
}
private void bhasil_Click(object sender, EventArgs e)
{
b = Double.Parse(bil);
this.Hasil.Text = proseshasil(operatornya).ToString();
bil = "0";
a = 0;
b = 0;
}
private void b1_Click(object sender, EventArgs e)
{
if (bil != "0" || operatornya == "")
bil = bil + "1";
else
bil = "1";
this.Hasil.Text = bil;
}
private void b2_Click(object sender, EventArgs e)
{
if (bil != "0" || operatornya == "")
bil = bil + "2";
else
bil = "2";
this.Hasil.Text = bil;
}
private void b3_Click(object sender, EventArgs e)
{
if (bil != "0" || operatornya == "")
bil = bil + "3";
else
bil = "3";
this.Hasil.Text = bil;
}
private void b4_Click(object sender, EventArgs e)
{
if (bil != "0" || operatornya == "")
bil = bil + "4";
else
bil = "4";
this.Hasil.Text = bil;
}
private void b5_Click(object sender, EventArgs e)
{
if (bil != "0" || operatornya == "")
bil = bil + "5";
else
bil = "5";
this.Hasil.Text = bil;
}
private void b6_Click(object sender, EventArgs e)
{
if (bil != "0" || operatornya == "")
bil = bil + "6";
else
bil = "6";
this.Hasil.Text = bil;
}
private void b7_Click(object sender, EventArgs e)
{
if (bil != "0" || operatornya == "")
bil = bil + "7";
else
bil = "7";
this.Hasil.Text = bil;
}
private void b8_Click(object sender, EventArgs e)
{
if (bil != "0" || operatornya == "")
bil = bil + "8";
else
bil = "8";
this.Hasil.Text = bil;
}
private void b9_Click(object sender, EventArgs e)
{
if (bil != "0" || operatornya == "")
bil = bil + "9";
else
bil = "9";
this.Hasil.Text = bil;
}
private void b0_Click(object sender, EventArgs e)
{
if (bil != "0" || operatornya == "")
bil = bil + "0";
else
bil = "0";
this.Hasil.Text = bil;
}
private void bc_Click(object sender, EventArgs e)
{
a = 0;
b = 0;
c = 0;
bil = "";
operatornya = "";
Hasil.Text = "0";
}
private void btambah_Click(object sender, EventArgs e)
{
if (bil != "")
{
operatornya = "tambah";
if (a == 0)
{
a = Double.Parse(bil);
}
else
{
b = Double.Parse(bil);
a = proseshasil("tambah");
}
bil = "";
}
}
private void bkurang_Click(object sender, EventArgs e)
{
operatornya = "kurang";
if (a == 0)
{
a = Double.Parse(bil);
}
else
{
b = Double.Parse(bil);
a = proseshasil("kurang");
}
bil = "";
}
private void bminus_Click(object sender, EventArgs e)
{
double bilMinus = Double.Parse(bil) * -1;
bil = bilMinus.ToString();
this.Hasil.Text = bil;
}
private void bbagi_Click(object sender, EventArgs e)
{
{
if (a == 0)
{
a = Double.Parse(bil);
operatornya = "bagi";
}
else
{
b = Double.Parse(bil);
a = proseshasil("bagi");
operatornya = "bagi";
}
bil = "";
}
}
private void bhapus_Click(object sender, EventArgs e)
{
int jml = bil.Length;
if (jml > 0)
{
bil = bil.Substring(0, jml - 1);
this.Hasil.Text = bil;
}
}
private void btitik_Click(object sender, EventArgs e)
{
if (bil != "")
bil = bil + ",";
else
bil = "0";
this.Hasil.Text = bil;
}
}
}
0 comments:
Posting Komentar