-
Notifications
You must be signed in to change notification settings - Fork 0
/
(1)Calculator.cs
83 lines (62 loc) · 1.98 KB
/
(1)Calculator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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 First11111
{
public partial class Form1 : Form
{
Boolean cleardisplay;
String op;
float operand;
public Form1()
{
InitializeComponent();
}
private void operator_Click(object sender, EventArgs e)
{
if(op!="")
{
equal_Click(sender, e);
op = "";
}
op = ((Button)sender).Text;
operand = Convert.ToSingle(textBox1.Text);
cleardisplay = true;
}
private void operand_Click(object sender, EventArgs e)
{
if (((Button)sender).Text == "." && textBox1.Text.IndexOf(".") >= 0)
return;
if(cleardisplay==true)
{
textBox1.Clear();
cleardisplay = false;
}
textBox1.Text = textBox1.Text + ((Button)sender).Text;
}
private void Clear_Click(object sender, EventArgs e)
{
cleardisplay = false;
textBox1.Clear();
op = "";
operand = 0;
}
private void equal_Click(object sender, EventArgs e)
{
if (op == "+")
textBox1.Text = Convert.ToString(operand + Convert.ToSingle(textBox1.Text));
if (op == "-")
textBox1.Text = Convert.ToString(operand - Convert.ToSingle(textBox1.Text));
if (op == "*")
textBox1.Text = Convert.ToString(operand * Convert.ToSingle(textBox1.Text));
if (op == "/")
textBox1.Text = Convert.ToString(operand / Convert.ToSingle(textBox1.Text));
}
}
}