calculator sederhana
designlah form berikut;
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 calculator_sederhana
{
public partial class Form1 : Form
{
private double a1, a2, xhasil = 0;
private string op="";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
hasil.Enabled=false;
}
private void btntambah_Click(object sender, EventArgs e)
{
op = "+";
}
private void btnkurang_Click(object sender, EventArgs e)
{
op ="-";
}
private void btnkali_Click(object sender, EventArgs e)
{
op ="*";
}
private void btnbagi_Click(object sender, EventArgs e)
{
op ="/";
}
private void btnhasil_Click(object sender, EventArgs e)
{
a1 = double.Parse(bil1.Text);
a2 =double.Parse(bil2.Text);
switch(op) {
case "/" : xhasil = a1/a2;
break;
case "*" : xhasil = a1*a2;
break;
case "-" : xhasil = a1-a2;
break;
case "+" : xhasil = a1+a2;
break;
}
hasil.Text=xhasil.ToString();
}
}
}
0 comments:
Posting Komentar