0% found this document useful (0 votes)
44 views2 pages

Coding C# Kalkulator

The document contains code for a basic calculator application. It includes code to: 1) Handle button clicks for the main calculation functions like addition and subtraction by passing a count variable to a compute method. 2) Set the count variable and clear the display when the multiplication button is clicked. 3) Add digits to the display when number buttons are clicked. 4) Remove the last digit from the display when the backspace button is clicked. 5) Clear the entire display and reset the count when the clear button is clicked.

Uploaded by

Mely Afriani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

Coding C# Kalkulator

The document contains code for a basic calculator application. It includes code to: 1) Handle button clicks for the main calculation functions like addition and subtraction by passing a count variable to a compute method. 2) Set the count variable and clear the display when the multiplication button is clicked. 3) Add digits to the display when number buttons are clicked. 4) Remove the last digit from the display when the backspace button is clicked. 5) Clear the entire display and reset the count when the clear button is clicked.

Uploaded by

Mely Afriani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Hitungan

private void btnHasil_Click(object sender, EventArgs e)


{
compute(count);
}
public void compute(int count)
{
switch (count)
{
case 1:
ans = num1 - float.Parse(Hasil.Text);
Hasil.Text = ans.ToString();
break;
case 2:
ans = num1 + float.Parse(Hasil.Text);
Hasil.Text = ans.ToString();
break;
case 3:
ans = num1 * float.Parse(Hasil.Text);
Hasil.Text = ans.ToString();
break;
case 4:
ans = num1 / float.Parse(Hasil.Text);
Hasil.Text = ans.ToString();
break;
default:
break;
}
}

Tombol Fungsi
private void btnKali_Click(object sender, EventArgs e)
{
num1 = float.Parse(Hasil.Text);
Hasil.Clear();
Hasil.Focus();
count = 3;
}

Tombol Input
private void button15_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
Hasil.Text = Hasil.Text + b.Text;
}

Backspace
private void button1_Click_1(object sender, EventArgs e)
{
int lenght = Hasil.TextLength - 1;
string text = Hasil.Text;
Hasil.Clear();
for (int i = 0; i < lenght; i++)
Hasil.Text = Hasil.Text + text[i];
}

Clear
private void button6_Click(object sender, EventArgs e)
{
Hasil.Clear();
count = 0;
}

You might also like