I have to create a calculator with +,-,*,/, +/- ,clear, sin,cos,tan,mod.
I have working +,-,*,/,+/- and clear.
Can anybody told me how can I make work sin, cos, ta, mod?
here is what I have so far:
bool plus = false;
bool minus = false;
bool multiply = false;
bool divide = false;
bool modulus = false;
private void btNegative_Click(object sender, EventArgs e)
{
if (textBox1.Text.Contains("-"))
{
textBox1.Text = textBox1.Text.Remove(0, 1); //Remove "-" if it is
already in the text box
}
else
{
textBox1.Text = "-" + textBox1.Text;
}
}
//buttom +
private void btPlus_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
return;
}
else
{
plus = true; //we make the 'adding' true
textBox1.Tag = textBox1.Text; // storage the number
textBox1.Text = ""; //clear the text box
}
}
//buttom =
private void btequal_Click(object sender, EventArgs e)
{
if (plus)
{
decimal dec = Convert.ToDecimal(textBox1.Tag)+ Convert.ToDecimal(textBox1.Text);
textBox1.Text = dec.ToString();
}
if (multiply)
{
decimal dec = Convert.ToDecimal(textBox1.Tag) * Convert.ToDecimal(textBox1.Text); //will multiply the two values
textBox1.Text = dec.ToString();
}
if (minus)
{
decimal dec = Convert.ToDecimal(textBox1.Tag) - Convert.ToDecimal(textBox1.Text); //will substract the two values
textBox1.Text = dec.ToString();
}
if (divide)
{
decimal dec = Convert.ToDecimal(textBox1.Tag) / Convert.ToDecimal(textBox1.Text); //will divide the two values
textBox1.Text = dec.ToString();
}
}
//buttom -
private void btMinus_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
return;
}
else
{
minus = true; //we make the 'minus' true
textBox1.Tag = textBox1.Text; // storage the number
textBox1.Text = ""; //clear the text box
}
}
//buttom multiply
private void btMult_Click(object sender, EventArgs e)
{
if (textBox1.Text == "") //if nothing is in the text box, we are going to returm
{
return;
}
else
{
multiply = true; //we make the 'multiply' true
textBox1.Tag = textBox1.Text; // storage the number
textBox1.Text = ""; //clear the text box
}
}
//buttom /
private void btDiv_Click(object sender, EventArgs e)
{
if (textBox1.Text == "") //if nothing is in the text box, we are going to returm
{
return;
}
else
{
divide = true; //we make the 'divide' true
textBox1.Tag = textBox1.Text; // storage the number
textBox1.Text = ""; //clear the text box
}
}
//buttom clear
private void btClear_Click(object sender, EventArgs e)
{
plus = minus = multiply = divide = false; //we make all the operations iqual false
textBox1.Text = ""; //make the screen clear
textBox1.Tag = ""; //Cleat the tag where the information is storage
}